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
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];

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.