Get Latitude and Longitude using jQuery and Googles Geo Coding Service


/ Published in: jQuery
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.