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

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.