Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
85
rated 0 times [  90] [ 5]  / answers: 1 / hits: 21880  / 6 Years ago, thu, may 24, 2018, 12:00:00

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


More From » angular

 Answers
7

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
}

[#54357] Monday, May 21, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lucillemariselal

Total Points: 108
Total Questions: 97
Total Answers: 119

Location: Thailand
Member since Thu, May 6, 2021
3 Years ago
;