I'm programming in Angular with Openlayers library. I want to use this API : https://adresse.data.gouv.fr/api (the page is in french so I will explain the purpose)
The goal of this API is on the one hand to search some adresses on a map while building GeoJSON files and on the other hand to use a reverse geocoding. This is why I need geographical location from the user.
For example this request : http 'https://api-adresse.data.gouv.fr/search/?q=8 bd du port' will return all the streets in the world answering to the name "8 bd du port"
So I want to use the reverse geocoding and create a request like this : http 'https://api-adresse.data.gouv.fr/reverse/?lon=user_lon&lat=user_lat'
It is the best way to proceed ? I don't want to use an another API like Google one
You can use the HTML standard Geolocation api for this.
getLocation(): void{
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition((position)=>{
const longitude = position.coords.longitude;
const latitude = position.coords.latitude;
this.callApi(longitude, latitude);
});
} else {
console.log("No support for geolocation")
}
}
callApi(Longitude: number, Latitude: number){
const url = `https://api-adresse.data.gouv.fr/reverse/?lon=${Longitude}&lat=${Latitude}`
//Call API
}
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