Avatar of bkrenzin
bkrenzin
 asked on

Parse Address Components Using c# from googleapis XML

I have found this code that will give me that lat & lng of an address.  However, I am not experienced enough to figure out how to "modify" the code to parse the address component    "administrative_area_level_2"

void Main()
{
	
	var address = "301 s western 66720";
	var requestUri = string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=false", Uri.EscapeDataString(address));
	
	var request = WebRequest.Create(requestUri);
	var response = request.GetResponse();
	var xdoc = XDocument.Load(response.GetResponseStream());
	
	var result = xdoc.Element("GeocodeResponse").Element("result");
	var locationElement = result.Element("geometry").Element("location");
	var lat = locationElement.Element("lat");
	var lng = locationElement.Element("lng");
	
	Console.WriteLine(lat);
	Console.WriteLine(lng);

Open in new window

GIS/GPS ProgrammingXMLC#

Avatar of undefined
Last Comment
bkrenzin

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
bkrenzin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23