Taking data from a url

Asked

Viewed 142 times

1

I have a website url, http://universimmedia.pagesperso-orange.fr/geo/loc.htm, where I place an address and clicking on the 'Search' button the site gives me the coordinates of that address, latitude and longitude, blz! I copied the code of this site and I want the search, by the coordinates of this address, to be done without having to click the 'Search' button. I tried to put the function call in the form onload and it did not help.

Can someone give me a hand?

Thanks.

  • 1

    The site in question uses the Google Maps API. It would not be easier for you to directly use the Google API as well?

  • @Marcusvinicius, I tried and failed, said that the key, if I’m not mistaken, was not valid.

  • Have you created a key for the API? https://developers.google.com/maps/documentation/javascript/tutorial#api_key

  • @Marcusvinicius, that’s right! I followed a tutorial I took from http://www.w3schools.com/googleapi/default.asp. I can try again and if there are problems, again send the error warning.

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>
<div id="result"></div>

However, it is recommended that you use the Google API for Javascript (you should set up an API key in the Google API dashboard). Follow the step by step in https://developers.google.com/maps/documentation/javascript/tutorial#HTML5

  • I published the map with the Key API that I generated and continues to give the same problem. See the http://fluxojoin.com.br/google-maps-w3school.htmlwarning

1

  • It was this link that I managed the key API, @waveiro. .

  • Guys, I’m putting this div and it doesn’t show up on the screen: <div id="Googlemap" style="width:500px; height:380px;"></div> Have a problem if the page is in php?

Browser other questions tagged

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