Topic: How to retrieve location specific details (City, Country)

Yo Peeps.

We are using the following code as per the example on your site

 // Using Online Maps
    // Get user location using geo co-ordinates.
    public void GetLocationGeoCords()
    {
        // Try find location name by coordinates.
        OnlineMapsGoogleAPIQuery query = OnlineMapsFindLocation.Find(null, -25.799320220947266f + "," + 28.264362335205078f);
        query.OnComplete += OnQueryComplete;
    }

    // Using Online Maps
    // Callback function.
    private void OnQueryComplete(string s)
    {
        // Show response in console.
        Debug.Log(s);
    }

This is the RAW XML result we are getting:

<?xml version="1.0" encoding="UTF-8"?>
<GeocodeResponse>
<status>OK</status>
<result>
  <type>street_address</type>
  <formatted_address>337 Sandalwood Dr, Pretoria, 0049, South Africa</formatted_address>
  <address_component>
   <long_name>337</long_name>
   <short_name>337</short_name>
   <type>street_number</type>
  </address_component>
  <address_component>
   <long_name>Sandalwood Drive</long_name>
   <short_name>Sandalwood Dr</short_name>
   <type>route</type>
  </address_component>
  <address_component>
   <long_name>Newlands</long_name>
   <short_name>Newlands</short_name>
   <type>political</type>
   <type>sublocality</type>
   <type>sublocality_level_1</type>
  </address_component>
  <address_component>
   <long_name>Pretoria</long_name>
   <short_name>Pretoria</short_name>
   <type>locality</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>Pretoria</long_name>
   <short_name>Pretoria</short_name>
   <type>administrative_area_level_2</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>Gauteng</long_name>
   <short_name>GP</short_name>
   <type>administrative_area_level_1</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>South Africa</long_name>
   <short_name>ZA</short_name>
   <type>country</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>0049</long_name>
   <short_name>0049</short_name>
   <type>postal_code</type>
  </address_component>
  <geometry>
   <location>
    <lat>-25.7991600</lat>
    <lng>28.2646000</lng>
   </location>
   <location_type>ROOFTOP</location_type>
   <viewport>
    <southwest>
     <lat>-25.8005090</lat>
     <lng>28.2632510</lng>
    </southwest>
    <northeast>
     <lat>-25.7978110</lat>
     <lng>28.2659490</lng>
    </northeast>
   </viewport>
  </geometry>
  <place_id>ChIJ-RxZHM5glR4Rl5blIfWVHuo</place_id>
</result>
<result>
  <type>political</type>
  <type>sublocality</type>
  <type>sublocality_level_1</type>
  <formatted_address>Newlands, Pretoria, 0181, South Africa</formatted_address>
  <address_component>
   <long_name>Newlands</long_name>
   <short_name>Newlands</short_name>
   <type>political</type>
   <type>sublocality</type>
   <type>sublocality_level_1</type>
  </address_component>
  <address_component>
   <long_name>Pretoria</long_name>
   <short_name>Pretoria</short_name>
   <type>locality</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>Tshwane</long_name>
   <short_name>Tshwane</short_name>
   <type>administrative_area_level_3</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>Pretoria</long_name>
   <short_name>Pretoria</short_name>
   <type>administrative_area_level_2</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>Gauteng</long_name>
   <short_name>GP</short_name>
   <type>administrative_area_level_1</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>South Africa</long_name>
   <short_name>ZA</short_name>
   <type>country</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>0181</long_name>
   <short_name>0181</short_name>
   <type>postal_code</type>
  </address_component>
  <geometry>
   <location>
    <lat>-25.7917597</lat>
    <lng>28.2716653</lng>
   </location>
   <location_type>APPROXIMATE</location_type>
   <viewport>
    <southwest>
     <lat>-25.7999920</lat>
     <lng>28.2632890</lng>
    </southwest>
    <northeast>
     <lat>-25.7815210</lat>
     <lng>28.2785160</lng>
    </northeast>
   </viewport>
   <bounds>
    <southwest>
     <lat>-25.7999920</lat>
     <lng>28.2632890</lng>
    </southwest>
    <northeast>
     <lat>-25.7815210</lat>
     <lng>28.2785160</lng>
    </northeast>
   </bounds>
  </geometry>
  <place_id>ChIJMet7-sVglR4Rc1CGIBjdv_U</place_id>
</result>
<result>
  <type>locality</type>
  <type>political</type>
  <formatted_address>Pretoria, South Africa</formatted_address>
  <address_component>
   <long_name>Pretoria</long_name>
   <short_name>Pretoria</short_name>
   <type>locality</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>Tshwane</long_name>
   <short_name>Tshwane</short_name>
   <type>administrative_area_level_3</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>Pretoria</long_name>
   <short_name>Pretoria</short_name>
   <type>administrative_area_level_2</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>Gauteng</long_name>
   <short_name>GP</short_name>
   <type>administrative_area_level_1</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>South Africa</long_name>
   <short_name>ZA</short_name>
   <type>country</type>
   <type>political</type>
  </address_component>
  <geometry>
   <location>
    <lat>-25.7478676</lat>
    <lng>28.2292712</lng>
   </location>
   <location_type>APPROXIMATE</location_type>
   <viewport>
    <southwest>
     <lat>-25.9157700</lat>
     <lng>27.9505809</lng>
    </southwest>
    <northeast>
     <lat>-25.6015300</lat>
     <lng>28.4453200</lng>
    </northeast>
   </viewport>
   <bounds>
    <southwest>
     <lat>-25.9157700</lat>
     <lng>27.9505809</lng>
    </southwest>
    <northeast>
     <lat>-25.6015300</lat>
     <lng>28.4453200</lng>
    </northeast>
   </bounds>
  </geometry>
  <place_id>ChIJM1DGvpxhlR4RTHuEerBiYvY</place_id>
</result>
<result>
  <type>postal_code</type>
  <formatted_address>Pretoria, 0049, South Africa</formatted_address>
  <address_component>
   <long_name>0049</long_name>
   <short_name>0049</short_name>
   <type>postal_code</type>
  </address_component>
  <address_component>
   <long_name>Pretoria</long_name>
   <short_name>Pretoria</short_name>
   <type>locality</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>Tshwane</long_name>
   <short_name>Tshwane</short_name>
   <type>administrative_area_level_3</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>Pretoria</long_name>
   <short_name>Pretoria</short_name>
   <type>administrative_area_level_2</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>Gauteng</long_name>
   <short_name>GP</short_name>
   <type>administrative_area_level_1</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>South Africa</long_name>
   <short_name>ZA</short_name>
   <type>country</type>
   <type>political</type>
  </address_component>
  <geometry>
   <location>
    <lat>-25.7917597</lat>
    <lng>28.2716653</lng>
   </location>
   <location_type>APPROXIMATE</location_type>
   <viewport>
    <southwest>
     <lat>-25.7999920</lat>
     <lng>28.2632890</lng>
    </southwest>
    <northeast>
     <lat>-25.7815210</lat>
     <lng>28.2785160</lng>
    </northeast>
   </viewport>
   <bounds>
    <southwest>
     <lat>-25.7999920</lat>
     <lng>28.2632890</lng>
    </southwest>
    <northeast>
     <lat>-25.7815210</lat>
     <lng>28.2785160</lng>
    </northeast>
   </bounds>
  </geometry>
  <place_id>ChIJMet7-sVglR4Rb7StmUZwGGU</place_id>
</result>
<result>
  <type>postal_code</type>
  <formatted_address>Pretoria, 0181, South Africa</formatted_address>
  <address_component>
   <long_name>0181</long_name>
   <short_name>0181</short_name>
   <type>postal_code</type>
  </address_component>
  <address_component>
   <long_name>Pretoria</long_name>
   <short_name>Pretoria</short_name>
   <type>locality</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>Tshwane</long_name>
   <short_name>Tshwane</short_name>
   <type>administrative_area_level_3</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>Pretoria</long_name>
   <short_name>Pretoria</short_name>
   <type>administrative_area_level_2</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>Gauteng</long_name>
   <short_name>GP</short_name>
   <type>administrative_area_level_1</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>South Africa</long_name>
   <short_name>ZA</short_name>
   <type>country</type>
   <type>political</type>
  </address_component>
  <geometry>
   <location>
    <lat>-25.8163149</lat>
    <lng>28.2643567</lng>
   </location>
   <location_type>APPROXIMATE</location_type>
   <viewport>
    <southwest>
     <lat>-25.9157700</lat>
     <lng>28.1603760</lng>
    </southwest>
    <northeast>
     <lat>-25.7564580</lat>
     <lng>28.3518330</lng>
    </northeast>
   </viewport>
   <bounds>
    <southwest>
     <lat>-25.9157700</lat>
     <lng>28.1603760</lng>
    </southwest>
    <northeast>
     <lat>-25.7564580</lat>
     <lng>28.3518330</lng>
    </northeast>
   </bounds>
  </geometry>
  <place_id>ChIJpx_jD_5mlR4R_ZCXmWFXJHc</place_id>
</result>
<result>
  <type>administrative_area_level_3</type>
  <type>political</type>
  <formatted_address>Tshwane, South Africa</formatted_address>
  <address_component>
   <long_name>Tshwane</long_name>
   <short_name>Tshwane</short_name>
   <type>administrative_area_level_3</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>Pretoria</long_name>
   <short_name>Pretoria</short_name>
   <type>administrative_area_level_2</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>Gauteng</long_name>
   <short_name>GP</short_name>
   <type>administrative_area_level_1</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>South Africa</long_name>
   <short_name>ZA</short_name>
   <type>country</type>
   <type>political</type>
  </address_component>
  <geometry>
   <location>
    <lat>-25.6975497</lat>
    <lng>28.1590786</lng>
   </location>
   <location_type>APPROXIMATE</location_type>
   <viewport>
    <southwest>
     <lat>-25.9449100</lat>
     <lng>27.8903500</lng>
    </southwest>
    <northeast>
     <lat>-25.3237100</lat>
     <lng>28.4453200</lng>
    </northeast>
   </viewport>
   <bounds>
    <southwest>
     <lat>-25.9449100</lat>
     <lng>27.8903500</lng>
    </southwest>
    <northeast>
     <lat>-25.3237100</lat>
     <lng>28.4453200</lng>
    </northeast>
   </bounds>
  </geometry>
  <place_id>ChIJjVNCr-ravx4R-HXigmr3_Cg</place_id>
</result>
<result>
  <type>administrative_area_level_2</type>
  <type>political</type>
  <formatted_address>Pretoria, South Africa</formatted_address>
  <address_component>
   <long_name>Pretoria</long_name>
   <short_name>Pretoria</short_name>
   <type>administrative_area_level_2</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>Gauteng</long_name>
   <short_name>GP</short_name>
   <type>administrative_area_level_1</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>South Africa</long_name>
   <short_name>ZA</short_name>
   <type>country</type>
   <type>political</type>
  </address_component>
  <geometry>
   <location>
    <lat>-25.6051205</lat>
    <lng>28.3929417</lng>
   </location>
   <location_type>APPROXIMATE</location_type>
   <viewport>
    <southwest>
     <lat>-26.0780899</lat>
     <lng>27.8903500</lng>
    </southwest>
    <northeast>
     <lat>-25.1096100</lat>
     <lng>29.0984199</lng>
    </northeast>
   </viewport>
   <bounds>
    <southwest>
     <lat>-26.0780899</lat>
     <lng>27.8903500</lng>
    </southwest>
    <northeast>
    <lat>-25.1096100</lat>
     <lng>29.0984199</lng>
    </northeast>
   </bounds>
  </geometry>
  <place_id>ChIJjVNCr-ravx4RPOYRWM0o7EU</place_id>
</result>
<result>
  <type>administrative_area_level_1</type>
  <type>political</type>
  <formatted_address>Gauteng, South Africa</formatted_address>
  <address_component>
   <long_name>Gauteng</long_name>
   <short_name>GP</short_name>
   <type>administrative_area_level_1</type>
   <type>political</type>
  </address_component>
  <address_component>
   <long_name>South Africa</long_name>
   <short_name>ZA</short_name>
   <type>country</type>
   <type>political</type>
  </address_component>
  <geometry>
   <location>
    <lat>-26.2707593</lat>
    <lng>28.1122679</lng>
   </location>
   <location_type>APPROXIMATE</location_type>
   <viewport>
    <southwest>
     <lat>-26.9102236</lat>
     <lng>27.1563400</lng>
    </southwest>
    <northeast>
     <lat>-25.1096100</lat>
     <lng>29.0984187</lng>
    </northeast>
   </viewport>
   <bounds>
    <southwest>
     <lat>-26.9102236</lat>
     <lng>27.1563400</lng>
    </southwest>
    <northeast>
     <lat>-25.1096100</lat>
     <lng>29.0984187</lng>
    </northeast>
   </bounds>
  </geometry>
  <place_id>ChIJn3cRVJUSlR4R4jhUy8fnnm0</place_id>
</result>
<result>
  <type>country</type>
  <type>political</type>
  <formatted_address>South Africa</formatted_address>
  <address_component>
   <long_name>South Africa</long_name>
   <short_name>ZA</short_name>
   <type>country</type>
   <type>political</type>
  </address_component>
  <geometry>
   <location>
    <lat>-30.5594820</lat>
    <lng>22.9375060</lng>
   </location>
   <location_type>APPROXIMATE</location_type>
   <viewport>
    <southwest>
     <lat>-34.8331569</lat>
     <lng>16.4536514</lng>
    </southwest>
    <northeast>
     <lat>-22.1254241</lat>
     <lng>32.8909911</lng>
    </northeast>
   </viewport>
   <bounds>
    <southwest>
     <lat>-46.9767945</lat>
     <lng>16.4536514</lng>
    </southwest>
    <northeast>
    <lat>-22.1254241</lat>
     <lng>38.0032997</lng>
    </northeast>
   </bounds>
  </geometry>
  <place_id>ChIJURLu2YmmNBwRoOikHwxjXeg</place_id>
</result>
</GeocodeResponse>

we have tried parsing the RAW XML ourselves but have not been with no success.

We are only looking for the following information:
   <long_name>Pretoria</long_name>
AND
   <long_name>South Africa</long_name>
OR (Ideally)
   <formatted_address>Pretoria, South Africa</formatted_address>

How can we extract the required details from the raw response data?
thank you for your time.

Re: How to retrieve location specific details (City, Country)

Hello.

Something like that:

OnlineMapsXML xml = OnlineMapsXML.Load(s);

OnlineMapsXML formatted_address = xml.Find("result[type = \"locality\"]/formatted_address");
Debug.Log(formatted_address.Value());

// or

OnlineMapsXML localityResult = xml.Find("result[type = \"locality\"]");
OnlineMapsXML country = localityResult.Find("address_component[type = \"country\"]/long_name");
OnlineMapsXML locality = localityResult.Find("address_component[type = \"locality\"]/long_name");

if (!country.isNull && !locality.isNull)
{
    Debug.Log(string.Format("{0}, {1}", locality.Value(), country.Value()));
}
Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: How to retrieve location specific details (City, Country)

your a ninja, what else is there to say.

Thank you, rock on!