7

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

Adrien
  • 165
  • 2
  • 3
  • 11
  • 1
    No duplicate, I don't want to use Google API, I search a way to do this with Angular – Adrien May 24 '18 at 13:37
  • The most upvoted answer indicates to use the browser's geolocation API. It only mentions google API as a workaround – David May 24 '18 at 13:41
  • This question is not answering mine, I want to know the best way to implements location with Angular (this is not the case in this post because I know that Angular is different) – Adrien May 24 '18 at 13:51
  • You question is about retrieval geographical position from users. Angular runs in the browser. The browser provides a geolocation API. I'm not sure what you want more... – David May 24 '18 at 14:03

1 Answers1

23

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
  }
Malcor
  • 2,667
  • 21
  • 29