Getting data from a url

1

I have the url of a website, link , where I put an address and clicking the ' Search 'the site gives me the coordinates of this address, latitude and longitude, blz! I copied the code of this site and I want the search, by the coordinates of that address, to be done without having to click the 'Search' button. I have tried to put the function call in form onload and it did not work.

Can anyone give me a hand?

Thanks.

    
asked by anonymous 04.05.2015 / 22:45

2 answers

3

I advise you to use the Google API directly. The following code snippet (using jQuery for Ajax request) gets the latitude and longitude of an address passed by parameter:

$(document).ready(function() {
  var endereco = encodeURIComponent("Praça dos Três Poderes - Brasília");
  $.get("http://maps.google.com/maps/api/geocode/json?address=" + endereco,
    function(data) {
      if (data.status == "ZERO_RESULTS") {
        $("#result").html("Endereço não encontrado!");
        return;
      }

      var latitude = data.results[0].geometry.location.lat;
      var longitude = data.results[0].geometry.location.lng;
      $("#result").html("Latitude: " + latitude + "<br/>Longitude: " + longitude);
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="result"></div>

However, it is recommended that you use the Google API for Javascript (you must configure an API key in the Google APIs control panel). Follow the walkthrough at link

    
04.05.2015 / 23:59
1

Here is the link to get the key that he commented on to use the Google API: link

However, it is important to remember that, as written in the documentation:

  

If your app's Maps API usage exceeds usage limits, you must load the Maps API using an API key to acquire additional quota.

    
05.05.2015 / 02:00