Posted By

dave333 on 08/06/08


Tagged

google code longitude zip latitude postcode uk


Versions (?)

Who likes this?

18 people have marked this snippet as a favorite

chrisaiv
luman
stavelin
wizard04
carlosabargues
ikimozu
nb109
vali29
ignace
loric
Pixelpower
JimBarrows
kaartz
mecha
adth
arucordoba
Briantjuh
wirenaught


Find the Latitude and Longitude of a ZIP/Postcode using Google


 / Published in: PHP
 

Uses Google Maps API to find the latitude and longitude of a UK postcode (could easily be changed to US Zip Code by setting the URL to google.com).

I'm using file() here, but you might want to use curl..

  1. function GetLatLong($postcode){
  2. $myKey = 'Your_Google_API_Key_Here';
  3. $URL = "http://maps.google.co.uk/maps/geo?q=" . urlencode($postcode) . "&output=json&key=".$myKey;
  4.  
  5. $data = file($URL);
  6. if($data){
  7. $data = json_decode($data[0]);
  8.  
  9. $long = $data->Placemark[0]->Point->coordinates[0];
  10. $lat = $data->Placemark[0]->Point->coordinates[1];
  11.  
  12. return array('Latitude'=>$lat,'Longitude'=>$long);
  13.  
  14. }else return false;
  15.  
  16. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: naved_pasha06 on May 28, 2009

output=json $data = json_decode($data[0]);

I am not getting any output and by the way what this word jason means..??

I have made one class and caling this Fn from that clas by using object ..is it ok??

The browser is showing nothing...WHY????plz rply

Posted By: saravanat on March 23, 2011

Thanks for you script.. It help me to learn json .. i use this script for facebook application

Thanks again........................

Posted By: chrisaiv on June 23, 2011

@saravanat Happy to help.

You need to login to post a comment.