Posted By

Blerx on 01/27/12


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite


Get Latitude and Longitude using jQuery and Googles Geo Coding Service

 / Published in: jQuery

Nice ajax function to grab the latitude and longitude of an address or postcode. Don't forget your google key and address formatting.

  1. <script>
  2. jQuery(document).ready(function(){
  3. var jsapiKey = "YOUR API KEY";
  4. var address = "YOUR+ADDRESS";
  5. jQuery.getJSON(""+address+"&key="+jsapiKey+"&sensor=true&output=json&callback=?",
  6. function(data, textStatus){
  7. console.log("Latitude: "+data.Placemark[0].Point.coordinates[1]);
  8. console.log("Longitude: "+data.Placemark[0].Point.coordinates[0]);
  9. });
  10. });
  11. </script>

Report this snippet  

You need to login to post a comment.