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>
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
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.
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).
Mapbox SDKs collect de-identified data and device location to continuously update and improve your maps.
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);
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With