Click here to Skip to main content
16,012,107 members

Comments by Member 3810915 (Top 1 by date)

Member 3810915 11-Dec-11 9:01am View    
Deleted
Thank you for the fantastic example; voting it a 5!. It saved me lots of time. In appreciation and to the community, I'm attaching a demonstrative snippet showing a simple way of parsing out values from the GeoCodeResponse XML result.

<pre lang="c#">
if (geocodeResponse.Status == "OK")
{
for (int i = 0; i < geocodeResponse.Result[0].AddressComponent.GetLength(0); i++)
{
string tmp = geocodeResponse.Result[0].AddressComponent[i].Type[0].Value;
//
if (tmp == "street_number")
gAddress1.Text = geocodeResponse.Result[0].AddressComponent[i].LongName + " ";
else if (tmp == "route")
gAddress1.Text = gAddress1.Text + geocodeResponse.Result[0].AddressComponent[i].LongName;
else if (tmp == "locality")
gCity.Text = geocodeResponse.Result[0].AddressComponent[i].LongName;
else if (tmp == "administrative_area_level_1")
gState.Text = geocodeResponse.Result[0].AddressComponent[i].ShortName; // 2 letter state
else if (tmp == "postal_code")
gPostalCode.Text = geocodeResponse.Result[0].AddressComponent[i].LongName;
}
//
Lit.Text = geocodeResponse.Result[0].FormattedAddress;
// Sometimes the "sublocality" (verses "locality") is correct and other times not.
// Example are New York City addresses; Brooklyn and NYC
// Compare the two and if different set the City from the Formatted Address
string[] addrSplit = Lit.Text.Split(',');
if (gCity.Text.Trim().ToLower() != addrSplit[1].Trim().ToLower())
gCity.Text = addrSplit[1].Trim();
//
Lattitude.Text = geocodeResponse.Result[0].Geometry[0].Location[0].Lattitude;
Longitude.Text = geocodeResponse.Result[0].Geometry[0].Location[0].Longitude;
viewpointSWLat.Text = geocodeResponse.Result[0].Geometry[0].Viewport[0].SouthWest[0].Lattitude;
viewpointSWLon.Text = geocodeResponse.Result[0].Geometry[0].Viewport[0].SouthWest[0].Longitude;
viewpointNELat.Text = geocodeResponse.Result[0].Geometry[0].Viewport[0].NorthEast[0].Lattitude;
viewpointNELon.Text = geocodeResponse.Result[0].Geometry[0].Viewport[0].NorthEast[0].Longitude;
gCompare.Text = String.Format("{0}", geocodeFailsCompare());
}
</pre>