How to find an address by latitude and longitude

Asked

Viewed 16,310 times

7

How do I get the full address of a geolocation, ex:

Lat. 37.386196601958
Lon. -121.964346639

(Street tal, Neighborhood tal, cep: tal)

  • 1

    Very broad question. Have any attempt?

  • I’m sorry, I have no idea. I use an API for geolocation and a Google Places API that returns my addresses. Only the Google Places API sometimes doesn’t return the full Geolocation address, so I’ll have to search manually to compose my address information by Xtendo!!! I was clear?

  • 1

    So it’s google api that will use... Ask clearer questions, your question doesn’t even tell you which API to use, we were assuming it was some mobile api, like native GPS.

  • But friend, the question is not how I’m getting geolocation, I could be using the HTML5 Native Geolocation API that wouldn’t make a difference, the point is I need the full address! And I wouldn’t want to use another API like Google Maps because they have a limit of daily requests, so to be charged. I wanted to know if there is something native to html 5 or some javascript api or even web free api.

2 answers

6


Use the API geolocation provided by Google:

https://maps.googleapis.com/maps/api/geocode/output?parameters

The output sets the response format, either JSON or XML. The parameters depend on the type of information you are looking for, further details can be found in documentation. A simple search for latitude and longitude could be done as follows:

http://maps.googleapis.com/maps/api/geocode/json?latlng=37.386196601958,-121.964346639
  • Nice @Renan, this I hadn’t used yet, and the good thing is that I don’t need to consume from my daily "quota" margin. I think I’ll use this!

1

If you want an Opensource/Free solution, use the service Verse of Openstreet. Would look like a request ajax:

  reqwest({
      url: 'http://nominatim.openstreetmap.org/reverse?',
      method: 'get',
      crossOrigin: true,
      type: 'json',
      data: {
          format: 'json',
          lat: latitude,
          lon: longitude,
          addressdetails: 1,
          'accept-language': 'pt-BR',
          zoom: 18
      }
  }).then(function (response) {
        console.info(response);
    msg_el.innerHTML = response.display_name;
  }).fail(function (err, msg) {
      console.info(err, msg);
  });

http://jsfiddle.net/jonataswalker/LdpcyL6o/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.