Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8687833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:12:26+00:00 2026-06-12T23:12:26+00:00

I am using the Google map API V3 making a request with lat/lng, with

  • 0

I am using the Google map API V3 making a request with lat/lng, with the expectation of getting the full address data returned. However, my PHP program would fail to get, for example, the Zip Code returned sometimes. I did a var_dump of what’s being returned. I see an extra object element, which may be the cause I’m not sure. It’s entirely possible I don’t know everything about how Objects in PHP work too. Here is the var_dump output for the area of interest. The first example does indeed return the Zip Code to my PHP program making the request while the second one fails to do so and gives an error of “Trying to get property of non-object…”. Thanks in advance for taking a look on this and your useful comments.

This is the var_dump of $xml that is returned from Google Map API V3, which DOES NOT WORK and fails to return the zip code properly:

object(SimpleXMLElement)#1 (1) {
  ["Response"]=>
  object(SimpleXMLElement)#2 (3) {
    ["name"]=>
    string(24) "40.74005999,-73.99718229"
    ["Status"]=>
    object(SimpleXMLElement)#3 (2) {
      ["code"]=>
      string(3) "200"
      ["request"]=>
      string(7) "geocode"
    }
    ["Placemark"]=>
    object(SimpleXMLElement)#4 (5) {
      ["@attributes"]=>
      array(1) {
        ["id"]=>
        string(2) "p1"
      }
      ["address"]=>
      string(38) "136 W 17th St, New York, NY 10011, USA"
      ["AddressDetails"]=>
      object(SimpleXMLElement)#5 (2) {
        ["@attributes"]=>
        array(1) {
          ["Accuracy"]=>
          string(1) "8"
        }
        ["Country"]=>
        object(SimpleXMLElement)#8 (3) {
          ["CountryNameCode"]=>
          string(2) "US"
          ["CountryName"]=>
          string(3) "USA"
          ["AdministrativeArea"]=>
          object(SimpleXMLElement)#9 (2) {
            ["AdministrativeAreaName"]=>
            string(2) "NY"
            ["SubAdministrativeArea"]=>
            object(SimpleXMLElement)#10 (2) {
              ["SubAdministrativeAreaName"]=>
              string(8) "New York"
              ["Locality"]=>
              object(SimpleXMLElement)#11 (2) {
                ["LocalityName"]=>
                string(8) "New York"
                ["DependentLocality"]=>
                object(SimpleXMLElement)#12 (3) {
                  ["DependentLocalityName"]=>
                  string(9) "Manhattan"
                  ["Thoroughfare"]=>
                  object(SimpleXMLElement)#13 (1) {
                    ["ThoroughfareName"]=>
                    string(13) "136 W 17th St"
                  }
                  ["PostalCode"]=>
                  object(SimpleXMLElement)#14 (1) {
                    ["PostalCodeNumber"]=>
                    string(5) "10011"
                  }
                }
              }
            }
          }
        }
      }
      ["ExtendedData"]=>
      object(SimpleXMLElement)#6 (1) {
        ["LatLonBox"]=>
        object(SimpleXMLElement)#8 (1) {
          ["@attributes"]=>
          array(4) {
            ["north"]=>
            string(10) "40.7414089"
            ["south"]=>
            string(10) "40.7387109"
            ["east"]=>
            string(11) "-73.9958332"
            ["west"]=>
            string(11) "-73.9985312"
          }
        }
      }
      ["Point"]=>
      object(SimpleXMLElement)#7 (1) {
        ["coordinates"]=>
        string(24) "-73.9971822,40.7400599,0"
      }
    }
  }
}

The above has these errors:

PHP Notice:  Trying to get property of non-object in try.php on line 38
PHP Notice:  Trying to get property of non-object in try.php on line 41

Here is the PHP code for those lines:

$status = $xml->Response->Status->code;
// Country
$country = $xml->Response->Placemark->AddressDetails->Country;
$country_code = $country->CountryNameCode;
$country_name = $country->CountryName;

// Address
$address_line = $xml->Response->Placemark->address;

// Street address
$Locality = $country->AdministrativeArea->Locality;
// var_dump($Locality);
$street = $country->AdministrativeArea->Locality->Thoroughfare->ThoroughfareName;
$city = $country->AdministrativeArea->Locality->LocalityName;
$state = $country->AdministrativeArea->AdministrativeAreaName;
$zip_code = $country->AdministrativeArea->Locality->PostalCode->PostalCodeNumber;

Line 41 is the last line of code with the $zip_code, and line 38 is the line of code which begins with $street.

You will notice the above contains a [“SubAdministrativeArea”]=> which the working example below does not. Does this matter?

object(SimpleXMLElement)#1 (1) {
  ["Response"]=>
  object(SimpleXMLElement)#2 (3) {
    ["name"]=>
    string(24) "40.74445606,-73.97495072"
    ["Status"]=>
    object(SimpleXMLElement)#3 (2) {
      ["code"]=>
      string(3) "200"
      ["request"]=>
      string(7) "geocode"
    }
    ["Placemark"]=>
    object(SimpleXMLElement)#4 (5) {
      ["@attributes"]=>
      array(1) {
        ["id"]=>
        string(2) "p1"
      }
      ["address"]=>
      string(38) "317 E 34th St, New York, NY 10016, USA"
      ["AddressDetails"]=>
      object(SimpleXMLElement)#5 (2) {
        ["@attributes"]=>
        array(1) {
          ["Accuracy"]=>
          string(1) "8"
        }
        ["Country"]=>
        object(SimpleXMLElement)#8 (3) {
          ["CountryNameCode"]=>
          string(2) "US"
          ["CountryName"]=>
          string(3) "USA"
          ["AdministrativeArea"]=>
          object(SimpleXMLElement)#9 (2) {
            ["AdministrativeAreaName"]=>
            string(2) "NY"
            ["Locality"]=>
            object(SimpleXMLElement)#10 (3) {
              ["LocalityName"]=>
              string(8) "New York"
              ["Thoroughfare"]=>
              object(SimpleXMLElement)#11 (1) {
                ["ThoroughfareName"]=>
                string(13) "317 E 34th St"
              }
              ["PostalCode"]=>
              object(SimpleXMLElement)#12 (1) {
                ["PostalCodeNumber"]=>
                string(5) "10016"
              }
            }
          }
        }
      }
      ["ExtendedData"]=>
      object(SimpleXMLElement)#6 (1) {
        ["LatLonBox"]=>
        object(SimpleXMLElement)#8 (1) {
          ["@attributes"]=>
          array(4) {
            ["north"]=>
            string(10) "40.7458050"
            ["south"]=>
            string(10) "40.7431070"
            ["east"]=>
            string(11) "-73.9736017"
            ["west"]=>
            string(11) "-73.9762997"
          }
        }
      }
      ["Point"]=>
      object(SimpleXMLElement)#7 (1) {
        ["coordinates"]=>
        string(24) "-73.9749507,40.7444560,0"
      }
    }
  }
}

And here are the lines of code used to output which the $zip_code is blank for the first example, while with the second one it does work as expected.

echo "===================================\n";
echo "Status code is: " . $status . "\n";
echo "address line is:" . $address_line . "\n";
echo "=+=+=" . "\n";
echo "street is: " . $street . "\n";
echo "city is: " . $city . "\n";
echo "state is: " . $state . "\n";
echo "zip code is: " . $zip_code . "\n";
echo "country code is: " . $country_code . "\n";
echo "country name is: " . $country_name. "\n";

The different locations used in this example are both in New York City. I don’t know why one is working while the other is not, expect I see it’s returning the [“SubAdministrativeArea”]. Shouldn’t the Google map API V3 return the same format of information for the same area? Is this even a factor in the problem I’m having? Am I not handling the objects and elements correctly? If so, please enlighten me because I am stuck at this point.

Or should I be checking for two different situations which might be returned (or more?) by the Google map API V3? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:12:27+00:00Added an answer on June 12, 2026 at 11:12 pm

    You will notice the above contains a [“SubAdministrativeArea”]=> which the working example below does not. Does this matter?

    Yes it matters.

    Shouldn’t the Google map API V3 return the same format of information for the same area?

    Some elements of the answer will always be present at the same place in the result tree but some others depend on the request. I can’t help you more on this as I never understood why there was sometimes more sublevels even if requests were very similar…

    Is this even a factor in the problem I’m having?

    Yes, because you can’t rely on a fixed result structure.

    Should I be checking for two different situations which might be returned (or more?) by the Google map API V3?

    Another solution can be to use an other library than SimpleXML to handle the result, like DOM, which has functions to find children through a tree, like DOMElement::getElementsByTagName. Getting values needs a bit more coding than with SimpleXML but this way you don’t need to check if there is a SubAdministrativeArea level or not.

    I hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the Google Maps API to build a map full of markers, but
I am using Google Map API to do address translation(mainly by geocoder ). And
I am getting driving distance from google map api v3 using this code. distance11
I am getting Uncaught TypeError while using Google Map API V3 Javascript Library. I
I have a site where i am using Google Map API v2 and google
I have a scenario where I am using Google Map JavaScript API to process
I have an application where I'm using the Google Map API to display markers
I am currently using Google API to point the position on Google map. this
I have a google map using V3 of the API. It has one marker
I have the following problem. I have embedded a map using Google Maps' API.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.