title: How do I retrieve data from google map API's
body: <p>I am trying to retrieve the long and lat values by converting a place name (E.g. london) into lang and lat values.
  I am using this API:
  <a href="http://maps.googleapis.com/maps/api/geocode/xml?address=" rel="nofollow">http://maps.googleapis.com/maps/api/geocode/xml?address=</a></p>
  
  <p>Here is the request:<br>
  maps.googleapis.com/maps/api/geocode/xml?address=london&amp;sensor=false</p>
  
  <p>This is the XML document it gives back to me:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;GeocodeResponse&gt;
   &lt;status&gt;OK&lt;/status&gt;
   &lt;result&gt;
    &lt;type&gt;locality&lt;/type&gt;
    &lt;type&gt;political&lt;/type&gt;
    &lt;formatted_address&gt;London, UK&lt;/formatted_address&gt;
    &lt;address_component&gt;
     &lt;long_name&gt;London&lt;/long_name&gt;
     &lt;short_name&gt;London&lt;/short_name&gt;
     &lt;type&gt;locality&lt;/type&gt;
     &lt;type&gt;political&lt;/type&gt;
    &lt;/address_component&gt;
    &lt;address_component&gt;
     &lt;long_name&gt;England&lt;/long_name&gt;
     &lt;short_name&gt;England&lt;/short_name&gt;
     &lt;type&gt;administrative_area_level_1&lt;/type&gt;
     &lt;type&gt;political&lt;/type&gt;
    &lt;/address_component&gt;
    &lt;address_component&gt;
     &lt;long_name&gt;United Kingdom&lt;/long_name&gt;
     &lt;short_name&gt;GB&lt;/short_name&gt;
     &lt;type&gt;country&lt;/type&gt;
     &lt;type&gt;political&lt;/type&gt;
    &lt;/address_component&gt;
    &lt;address_component&gt;
     &lt;long_name&gt;London&lt;/long_name&gt;
     &lt;short_name&gt;London&lt;/short_name&gt;
     &lt;type&gt;postal_town&lt;/type&gt;
    &lt;/address_component&gt;
    &lt;geometry&gt;
     &lt;location&gt;
      &lt;lat&gt;51.5081289&lt;/lat&gt;
      &lt;lng&gt;-0.1280050&lt;/lng&gt;
     &lt;/location&gt;
     &lt;location_type&gt;APPROXIMATE&lt;/location_type&gt;
     &lt;viewport&gt;
      &lt;southwest&gt;
       &lt;lat&gt;51.3968770&lt;/lat&gt;
       &lt;lng&gt;-0.3841238&lt;/lng&gt;
      &lt;/southwest&gt;
      &lt;northeast&gt;
       &lt;lat&gt;51.6191098&lt;/lat&gt;
       &lt;lng&gt;0.1281138&lt;/lng&gt;
      &lt;/northeast&gt;
     &lt;/viewport&gt;
     &lt;bounds&gt;
      &lt;southwest&gt;
       &lt;lat&gt;51.3849401&lt;/lat&gt;
       &lt;lng&gt;-0.3514684&lt;/lng&gt;
      &lt;/southwest&gt;
      &lt;northeast&gt;
       &lt;lat&gt;51.6723432&lt;/lat&gt;
       &lt;lng&gt;0.1482710&lt;/lng&gt;
      &lt;/northeast&gt;
     &lt;/bounds&gt;
    &lt;/geometry&gt;
   &lt;/result&gt;
   &lt;result&gt;
    &lt;type&gt;locality&lt;/type&gt;
    &lt;type&gt;political&lt;/type&gt;
    &lt;formatted_address&gt;London, ON, Canada&lt;/formatted_address&gt;
    &lt;address_component&gt;
     &lt;long_name&gt;London&lt;/long_name&gt;
     &lt;short_name&gt;London&lt;/short_name&gt;
     &lt;type&gt;locality&lt;/type&gt;
     &lt;type&gt;political&lt;/type&gt;
    &lt;/address_component&gt;
    &lt;address_component&gt;
     &lt;long_name&gt;Middlesex County&lt;/long_name&gt;
     &lt;short_name&gt;Middlesex County&lt;/short_name&gt;
     &lt;type&gt;administrative_area_level_2&lt;/type&gt;
     &lt;type&gt;political&lt;/type&gt;
    &lt;/address_component&gt;
    &lt;address_component&gt;
     &lt;long_name&gt;Ontario&lt;/long_name&gt;
     &lt;short_name&gt;ON&lt;/short_name&gt;
     &lt;type&gt;administrative_area_level_1&lt;/type&gt;
     &lt;type&gt;political&lt;/type&gt;
    &lt;/address_component&gt;
    &lt;address_component&gt;
     &lt;long_name&gt;Canada&lt;/long_name&gt;
     &lt;short_name&gt;CA&lt;/short_name&gt;
     &lt;type&gt;country&lt;/type&gt;
     &lt;type&gt;political&lt;/type&gt;
    &lt;/address_component&gt;
    &lt;geometry&gt;
     &lt;location&gt;
      &lt;lat&gt;42.9793980&lt;/lat&gt;
      &lt;lng&gt;-81.2461380&lt;/lng&gt;
     &lt;/location&gt;
     &lt;location_type&gt;APPROXIMATE&lt;/location_type&gt;
     &lt;viewport&gt;
      &lt;southwest&gt;
       &lt;lat&gt;42.8245170&lt;/lat&gt;
       &lt;lng&gt;-81.3908520&lt;/lng&gt;
      &lt;/southwest&gt;
      &lt;northeast&gt;
       &lt;lat&gt;43.0732450&lt;/lat&gt;
       &lt;lng&gt;-81.1063880&lt;/lng&gt;
      &lt;/northeast&gt;
     &lt;/viewport&gt;
     &lt;bounds&gt;
      &lt;southwest&gt;
       &lt;lat&gt;42.8245170&lt;/lat&gt;
       &lt;lng&gt;-81.3908520&lt;/lng&gt;
      &lt;/southwest&gt;
      &lt;northeast&gt;
       &lt;lat&gt;43.0732450&lt;/lat&gt;
       &lt;lng&gt;-81.1063880&lt;/lng&gt;
      &lt;/northeast&gt;
     &lt;/bounds&gt;
    &lt;/geometry&gt;
   &lt;/result&gt;
   &lt;result&gt;
    &lt;type&gt;locality&lt;/type&gt;
    &lt;type&gt;political&lt;/type&gt;
    &lt;formatted_address&gt;London, KY, USA&lt;/formatted_address&gt;
    &lt;address_component&gt;
     &lt;long_name&gt;London&lt;/long_name&gt;
     &lt;short_name&gt;London&lt;/short_name&gt;
     &lt;type&gt;locality&lt;/type&gt;
     &lt;type&gt;political&lt;/type&gt;
    &lt;/address_component&gt;
    &lt;address_component&gt;
     &lt;long_name&gt;Laurel&lt;/long_name&gt;
     &lt;short_name&gt;Laurel&lt;/short_name&gt;
     &lt;type&gt;administrative_area_level_2&lt;/type&gt;
     &lt;type&gt;political&lt;/type&gt;
    &lt;/address_component&gt;
    &lt;address_component&gt;
     &lt;long_name&gt;Kentucky&lt;/long_name&gt;
     &lt;short_name&gt;KY&lt;/short_name&gt;
     &lt;type&gt;administrative_area_level_1&lt;/type&gt;
     &lt;type&gt;political&lt;/type&gt;
    &lt;/address_component&gt;
    &lt;address_component&gt;
     &lt;long_name&gt;United States&lt;/long_name&gt;
     &lt;short_name&gt;US&lt;/short_name&gt;
     &lt;type&gt;country&lt;/type&gt;
     &lt;type&gt;political&lt;/type&gt;
    &lt;/address_component&gt;
    &lt;geometry&gt;
     &lt;location&gt;
      &lt;lat&gt;37.1289771&lt;/lat&gt;
      &lt;lng&gt;-84.0832646&lt;/lng&gt;
     &lt;/location&gt;
     &lt;location_type&gt;APPROXIMATE&lt;/location_type&gt;
     &lt;viewport&gt;
      &lt;southwest&gt;
       &lt;lat&gt;37.0797589&lt;/lat&gt;
       &lt;lng&gt;-84.1262620&lt;/lng&gt;
      &lt;/southwest&gt;
      &lt;northeast&gt;
       &lt;lat&gt;37.1522600&lt;/lat&gt;
       &lt;lng&gt;-84.0359570&lt;/lng&gt;
      &lt;/northeast&gt;
     &lt;/viewport&gt;
     &lt;bounds&gt;
      &lt;southwest&gt;
       &lt;lat&gt;37.0797589&lt;/lat&gt;
       &lt;lng&gt;-84.1262620&lt;/lng&gt;
      &lt;/southwest&gt;
      &lt;northeast&gt;
       &lt;lat&gt;37.1522600&lt;/lat&gt;
       &lt;lng&gt;-84.0359570&lt;/lng&gt;
      &lt;/northeast&gt;
     &lt;/bounds&gt;
    &lt;/geometry&gt;
   &lt;/result&gt;
   &lt;result&gt;
    &lt;type&gt;locality&lt;/type&gt;
    &lt;type&gt;political&lt;/type&gt;
    &lt;formatted_address&gt;London, OH 43140, USA&lt;/formatted_address&gt;
    &lt;address_component&gt;
     &lt;long_name&gt;London&lt;/long_name&gt;
     &lt;short_name&gt;London&lt;/short_name&gt;
     &lt;type&gt;locality&lt;/type&gt;
     &lt;type&gt;political&lt;/type&gt;
    &lt;/address_component&gt;
    &lt;address_component&gt;
     &lt;long_name&gt;Madison&lt;/long_name&gt;
     &lt;short_name&gt;Madison&lt;/short_name&gt;
     &lt;type&gt;administrative_area_level_2&lt;/type&gt;
     &lt;type&gt;political&lt;/type&gt;
    &lt;/address_component&gt;
    &lt;address_component&gt;
     &lt;long_name&gt;Ohio&lt;/long_name&gt;
     &lt;short_name&gt;OH&lt;/short_name&gt;
     &lt;type&gt;administrative_area_level_1&lt;/type&gt;
     &lt;type&gt;political&lt;/type&gt;
    &lt;/address_component&gt;
    &lt;address_component&gt;
     &lt;long_name&gt;United States&lt;/long_name&gt;
     &lt;short_name&gt;US&lt;/short_name&gt;
     &lt;type&gt;country&lt;/type&gt;
     &lt;type&gt;political&lt;/type&gt;
    &lt;/address_component&gt;
    &lt;address_component&gt;
     &lt;long_name&gt;43140&lt;/long_name&gt;
     &lt;short_name&gt;43140&lt;/short_name&gt;
     &lt;type&gt;postal_code&lt;/type&gt;
    &lt;/address_component&gt;
    &lt;geometry&gt;
     &lt;location&gt;
      &lt;lat&gt;39.8864493&lt;/lat&gt;
      &lt;lng&gt;-83.4482529&lt;/lng&gt;
     &lt;/location&gt;
     &lt;location_type&gt;APPROXIMATE&lt;/location_type&gt;
     &lt;viewport&gt;
      &lt;southwest&gt;
       &lt;lat&gt;39.8592800&lt;/lat&gt;
       &lt;lng&gt;-83.4789230&lt;/lng&gt;
      &lt;/southwest&gt;
      &lt;northeast&gt;
       &lt;lat&gt;39.9217860&lt;/lat&gt;
       &lt;lng&gt;-83.3899969&lt;/lng&gt;
      &lt;/northeast&gt;
     &lt;/viewport&gt;
     &lt;bounds&gt;
      &lt;southwest&gt;
       &lt;lat&gt;39.8592800&lt;/lat&gt;
       &lt;lng&gt;-83.4789230&lt;/lng&gt;
      &lt;/southwest&gt;
      &lt;northeast&gt;
       &lt;lat&gt;39.9217860&lt;/lat&gt;
       &lt;lng&gt;-83.3899969&lt;/lng&gt;
      &lt;/northeast&gt;
     &lt;/bounds&gt;
    &lt;/geometry&gt;
   &lt;/result&gt;
  &lt;/GeocodeResponse&gt;
  </code></pre>
  
  <p>I am parsing the XML with PHP.
  Here is my code:</p>
  
  <pre><code>$geoResponce = new SimpleXMLElement($response);
  $geoLocatonLat = $geoResponce-&gt;result[0]-&gt;geometry-&gt;location-&gt;lat;
  </code></pre>
  
  <p>But I just get null values
  Can you tell me where I am going wrong please.  Thanks</p>
  
  <p>ADDITION:
  here is my var_dump($geoResponce);  </p>
  
  <pre><code>ssobject(SimpleXMLElement)#108 (2) {
    ["status"]=&gt;
    string(2) "OK"
    ["result"]=&gt;
    object(SimpleXMLElement)#120 (5) {
      ["type"]=&gt;
      string(5) "route"
      ["formatted_address"]=&gt;
      string(32) "Eldonian Way, Liverpool L3 6, UK"
      ["address_component"]=&gt;
      array(8) {
        [0]=&gt;
        object(SimpleXMLElement)#121 (3) {
          ["long_name"]=&gt;
          string(12) "Eldonian Way"
          ["short_name"]=&gt;
          string(12) "Eldonian Way"
          ["type"]=&gt;
          string(5) "route"
        }
        [1]=&gt;
        object(SimpleXMLElement)#122 (3) {
          ["long_name"]=&gt;
          string(9) "Liverpool"
          ["short_name"]=&gt;
          string(9) "Liverpool"
          ["type"]=&gt;
          array(2) {
            [0]=&gt;
            string(8) "locality"
            [1]=&gt;
            string(9) "political"
          }
        }
        [2]=&gt;
        object(SimpleXMLElement)#123 (3) {
          ["long_name"]=&gt;
          string(9) "Liverpool"
          ["short_name"]=&gt;
          string(9) "Liverpool"
          ["type"]=&gt;
          array(2) {
            [0]=&gt;
            string(27) "administrative_area_level_3"
            [1]=&gt;
            string(9) "political"
          }
        }
        [3]=&gt;
        object(SimpleXMLElement)#124 (3) {
          ["long_name"]=&gt;
          string(9) "Liverpool"
          ["short_name"]=&gt;
          string(9) "Liverpool"
          ["type"]=&gt;
          array(2) {
            [0]=&gt;
            string(27) "administrative_area_level_2"
            [1]=&gt;
            string(9) "political"
          }
        }
        [4]=&gt;
        object(SimpleXMLElement)#125 (3) {
          ["long_name"]=&gt;
          string(7) "England"
          ["short_name"]=&gt;
          string(7) "England"
          ["type"]=&gt;
          array(2) {
            [0]=&gt;
            string(27) "administrative_area_level_1"
            [1]=&gt;
            string(9) "political"
          }
        }
        [5]=&gt;
        object(SimpleXMLElement)#126 (3) {
          ["long_name"]=&gt;
          string(14) "United Kingdom"
          ["short_name"]=&gt;
          string(2) "GB"
          ["type"]=&gt;
          array(2) {
            [0]=&gt;
            string(7) "country"
            [1]=&gt;
            string(9) "political"
          }
        }
        [6]=&gt;
        object(SimpleXMLElement)#127 (3) {
          ["long_name"]=&gt;
          string(4) "L3 6"
          ["short_name"]=&gt;
          string(4) "L3 6"
          ["type"]=&gt;
          array(2) {
            [0]=&gt;
            string(18) "postal_code_prefix"
            [1]=&gt;
            string(11) "postal_code"
          }
        }
        [7]=&gt;
        object(SimpleXMLElement)#128 (3) {
          ["long_name"]=&gt;
          string(9) "Liverpool"
          ["short_name"]=&gt;
          string(9) "Liverpool"
          ["type"]=&gt;
          string(11) "postal_town"
        }
      }
      ["geometry"]=&gt;
      object(SimpleXMLElement)#129 (4) {
        ["location"]=&gt;
        object(SimpleXMLElement)#130 (2) {
          ["lat"]=&gt;
          string(10) "53.4189242"
          ["lng"]=&gt;
          string(10) "-2.9926240"
        }
        ["location_type"]=&gt;
        string(16) "GEOMETRIC_CENTER"
        ["viewport"]=&gt;
        object(SimpleXMLElement)#131 (2) {
          ["southwest"]=&gt;
          object(SimpleXMLElement)#133 (2) {
            ["lat"]=&gt;
            string(10) "53.4171964"
            ["lng"]=&gt;
            string(10) "-2.9940368"
          }
          ["northeast"]=&gt;
          object(SimpleXMLElement)#134 (2) {
            ["lat"]=&gt;
            string(10) "53.4208640"
            ["lng"]=&gt;
            string(10) "-2.9913388"
          }
        }
        ["bounds"]=&gt;
        object(SimpleXMLElement)#132 (2) {
          ["southwest"]=&gt;
          object(SimpleXMLElement)#134 (2) {
            ["lat"]=&gt;
            string(10) "53.4171964"
            ["lng"]=&gt;
            string(10) "-2.9934545"
          }
          ["northeast"]=&gt;
          object(SimpleXMLElement)#133 (2) {
            ["lat"]=&gt;
            string(10) "53.4208640"
            ["lng"]=&gt;
            string(10) "-2.9919211"
          }
        }
      }
      ["partial_match"]=&gt;
      string(4) "true"
    }
  }
  enter code here
  enter code here
  enter code here
  </code></pre>