dk4210
01-13-2012, 11:56 AM
Hello Guys,
I need some help here.. I am trying to extract the lat and long from a json query from google.
Here is what I receive back from json
{
"name": "795PollardBlvdSW,Atlanta,GA",
"Status": {
"code": 200,
"request": "geocode"
},
"Placemark": [ {
"id": "p1",
"address": "Atlanta, GA, USA",
"AddressDetails": {
"Accuracy" : 4,
"Country" : {
"AdministrativeArea" : {
"AdministrativeAreaName" : "GA",
"SubAdministrativeArea" : {
"Locality" : {
"LocalityName" : "Atlanta"
},
"SubAdministrativeAreaName" : "Fulton"
}
},
"CountryName" : "USA",
"CountryNameCode" : "US"
}
},
"ExtendedData": {
"LatLonBox": {
"north": 33.8231844,
"south": 33.6747422,
"east": -84.2599230,
"west": -84.5160418
}
},
"Point": {
"coordinates": [ -84.3879824, 33.7489954, 0 ]
}
} ]
}
Here is the code I am using
$geocode=file_get_contents('http://maps.google.com/maps/geo?output=json&q=795PollardBlvdSW,Atlanta,GA');
$output= json_decode($geocode);
$lat = $output->results[0]->geometry->location->lat;
$long = $output->results[0]->geometry->location->lng;
echo $lat;
echo $long;
Just not sure how to pull the lat and long out of a json into vars..
Please advise..
Dan
I need some help here.. I am trying to extract the lat and long from a json query from google.
Here is what I receive back from json
{
"name": "795PollardBlvdSW,Atlanta,GA",
"Status": {
"code": 200,
"request": "geocode"
},
"Placemark": [ {
"id": "p1",
"address": "Atlanta, GA, USA",
"AddressDetails": {
"Accuracy" : 4,
"Country" : {
"AdministrativeArea" : {
"AdministrativeAreaName" : "GA",
"SubAdministrativeArea" : {
"Locality" : {
"LocalityName" : "Atlanta"
},
"SubAdministrativeAreaName" : "Fulton"
}
},
"CountryName" : "USA",
"CountryNameCode" : "US"
}
},
"ExtendedData": {
"LatLonBox": {
"north": 33.8231844,
"south": 33.6747422,
"east": -84.2599230,
"west": -84.5160418
}
},
"Point": {
"coordinates": [ -84.3879824, 33.7489954, 0 ]
}
} ]
}
Here is the code I am using
$geocode=file_get_contents('http://maps.google.com/maps/geo?output=json&q=795PollardBlvdSW,Atlanta,GA');
$output= json_decode($geocode);
$lat = $output->results[0]->geometry->location->lat;
$long = $output->results[0]->geometry->location->lng;
echo $lat;
echo $long;
Just not sure how to pull the lat and long out of a json into vars..
Please advise..
Dan