Jump to content

Google return latitude and longitude


teknojunkey

Recommended Posts

Hi can anyone help ?

 

I cant get this script to display the latitude and longitude :facewall:

 

I can see the file from this url that is created:

http://maps.google.co.uk/maps/geo?q=g783pj&output=json&key=ABQIAAAAAo5DJKafF5Wqy7iJIHvekxQDw6SbLitDXGRuCV60uhGEd-71JRQNyJ8twHQdwm4taRRWFLYUClMi7g

 

<?

$postcode = "glasgow";
$myKey = 'ABQIAAAAAo5DJKafF5Wqy7iJIHvekxQDw6SbLitDXGRuCV60uhGEd-71JRQNyJ8twHQdwm4taRRWFLYUClMi7g';
$URL = "http://maps.google.co.uk/maps/geo?q=" . urlencode($postcode) . "&output=json&key=".$myKey;


$data = file($URL);
$data = json_decode($data[0]);

$long = $data->Placemark[0]->Point->coordinates[1];
$lat = $data->Placemark[0]->Point->coordinates[2];

echo $URL;

return array('Latitude'=>$lat,'Longitude'=>$long);

echo $lat;
echo $long;

?>

 

but i cannot display the coordinates

 

I dont know much about json so this might be the problem

 

this is my server details

Apache/2.2.11 (Ubuntu) PHP/5.2.6-3ubuntu4.1

 

json

json support enabled

json version 1.2.1

 

thanks for any advice

Link to comment
https://forums.phpfreaks.com/topic/167812-google-return-latitude-and-longitude/
Share on other sites

instead of

$data = file($URL);
$data = json_decode($data[0]);

use

$data = json_decode(file_get_contents($URL));

 

and I think you want he 0 and 1 elements of the array, not 1 and 2:

$long = $data->Placemark[0]->Point->coordinates[0];
$lat = $data->Placemark[0]->Point->coordinates[1];

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.