Last active
July 6, 2021 11:03
-
-
Save sadewole/422c2c25502b1b17c9f6ca9a42ce9bac to your computer and use it in GitHub Desktop.
geocoding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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