Skip to content

Instantly share code, notes, and snippets.

@sadewole
Last active July 6, 2021 11:03
Show Gist options
  • Save sadewole/422c2c25502b1b17c9f6ca9a42ce9bac to your computer and use it in GitHub Desktop.
Save sadewole/422c2c25502b1b17c9f6ca9a42ce9bac to your computer and use it in GitHub Desktop.
geocoding
const fetchData = useCallback(() => {
const geocodingClient = mbxGeocoding({
accessToken: mapboxgl.accessToken,
});
// geocoding with countries
return geocodingClient
.forwardGeocode({
query: 'Ikeja, Lagos',
countries: ['ng'],
limit: 2,
})
.send()
.then((response) => {
const match = response.body;
const coordinates = match.features[0].geometry.coordinates;
const placeName = match.features[0].place_name;
const center = match.features[0].center;
return {
type: 'Feature',
center: center,
geometry: {
type: 'Point',
coordinates: coordinates,
},
properties: {
description: placeName,
},
};
});
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment