Geo Google get different items

I have the codes below to get full address from Geo API google. It works fine
but now I need to get address, city, state, and zip. And I have no idea how to get them in c#.
I read the following article as well but it is in javascript

https://stackoverflow.com/questions/10926420/how-do-i-get-just-the-postal-code-from-a-reverse-geocode-result 

        public static string GetAddress(string latitude, string longitude)
        {
            string locationName = "";
            string url = string.Format("https://maps.googleapis.com/maps/api/geocode/xml?latlng={0},{1}&sensor=false&key=AIzaSydsfBzalHtsdfsadfsadfasdfdsafTxZaIVQrePIK_Lfbv1QqPC_Xr5c", latitude, longitude);          
            XElement xml = XElement.Load(url);
            if (xml.Element("status").Value == "OK")
            {
                locationName = string.Format("{0}", xml.Element("result").Element("formatted_address").Value);                             
            }
            else
            {
                locationName = xml.Element("status").ToString();
            }
            return locationName;
        }

Open in new window

LVL 1
ITsolutionWizardAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ITsolutionWizardAuthor Commented:
any helps?
Sean Corcoran, JDCEO/CIOCommented:
Hello,

You could try something like this:

        public struct Address
        {
            public string formattedaddress;
            public string street;
            public string city;
            public string state;
            public string zip;
            public string country;
        }

        public static Address GetAddress(string latitude, string longitude)
        {
            string locationName = "";
            Address la = new Address();

            string url = string.Format("https://maps.googleapis.com/maps/api/geocode/xml?latlng={0},{1}&sensor=false&key=AIzaSydsfBzalHtsdfsadfsadfasdfdsafTxZaIVQrePIK_Lfbv1QqPC_Xr5c", latitude, longitude);
            XElement xml = XElement.Load(url);
            if (xml.Element("status").Value == "OK")
            {
                locationName = string.Format("{0}", xml.Element("result").Element("formatted_address").Value);

                string[] array = locationName.Split(',');
                string[] statezip = array[2].Trim().Split(' ');

                la.formattedaddress = locationName;
                la.street = array[0];
                la.city = array[1];
                la.state = statezip[0];
                la.zip = statezip[1];
                la.country = array[3];

            }
            else
            {
                locationName = xml.Element("status").ToString();
            }

            return la;
        }

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Google

From novice to tech pro — start learning today.