Jump to content

Extracting lat and long from google map json


dk4210

Recommended Posts

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

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.