Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve data from mapbox geocoder

i only need the mapbox geocoding autocomplete without the map (to put the result with lat/lng in another request)

I managed to put it totally alone without the map using this :

<template>
    <div id='geocoder' class='geocoder'></div>
</template>

<script>
import MapboxGeocoder from '@mapbox/mapbox-gl-geocoder'
require('../../node_modules/@mapbox/mapbox-gl-geocoder/dist/mapbox-gl-geocoder.css')

mapboxgl.accessToken = '<your access token here>';
var geocoder = new MapboxGeocoder({
    accessToken: mapboxgl.accessToken
    placeholder: 'Rechercher'
});
document.getElementById('geocoder').appendChild(geocoder.onAdd());
</script>

enter image description here

But now i would like to retrieve the data (specifically the lat/lng attribute in order to save it in my component and work with it)

How can i do that ? i've search through mapbox doc but did not found anything about that :/

Thanks in advance to the community

like image 665
foufrix Avatar asked Jul 18 '18 16:07

foufrix


People also ask

How do I get coordinates from Mapbox?

If you need to find a location's latitude and longitude, you can use the Mapbox Search playground, which allows you to search for a location and retrieve its coordinates in longitude,latitude format.

Does Mapbox have places API?

The Mapbox Geocoding API allows you to do forward and reverse geocoding operations. Forward Geocoding takes text in the form of an address or place and converts it to geographic coordinates (latitude/longitude).

Does Mapbox collect data?

Mapbox SDKs collect de-identified data and device location to continuously update and improve your maps.


Video Answer


1 Answers

From the API docs https://github.com/mapbox/mapbox-gl-geocoder/blob/master/API.md#on you can use

geocoder.on('results', function(results) {
   console.log(results);
})
like image 60
AndrewHarvey Avatar answered Sep 29 '22 17:09

AndrewHarvey