Posted By

Blerx on 01/27/12


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

AllKnightAccess
BrockSamsom


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("http://maps.google.com/maps/geo?q="+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.