teknojunkey Posted July 28, 2009 Share Posted July 28, 2009 Hi can anyone help ? I cant get this script to display the latitude and longitude 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 Quote Link to comment https://forums.phpfreaks.com/topic/167812-google-return-latitude-and-longitude/ Share on other sites More sharing options...
rhodesa Posted July 28, 2009 Share Posted July 28, 2009 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]; Quote Link to comment https://forums.phpfreaks.com/topic/167812-google-return-latitude-and-longitude/#findComment-885053 Share on other sites More sharing options...
teknojunkey Posted July 28, 2009 Author Share Posted July 28, 2009 Thanks so much the script works now Quote Link to comment https://forums.phpfreaks.com/topic/167812-google-return-latitude-and-longitude/#findComment-885108 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.