Reading Geocoding API XML in VB.NET

445 views
Skip to first unread message

Eric Mays

unread,
Apr 8, 2011, 1:16:25 AM4/8/11
to google-maps-ap...@googlegroups.com
Greetings,

Since the API switched from v2 to v3, and the XML output array has many similar nodes, I am having a problem reading any data except for the lat/long.

I have been trying different things so some of the code is commented out.

Again, all of this worked when the XML output had unique tags. I don't know how to specify a "type" tag to read such as "administrative_area_level_2" to get a county.

Thanks for your help,
Eric




Dim uriRequest As New Uri(GoogleMapsAPI_URL & _address & _output)
            Dim geoRequest As HttpWebRequest = WebRequest.Create(uriRequest)
            Dim geoResponse As HttpWebResponse = geoRequest.GetResponse()
            Dim sr As New StreamReader(geoResponse.GetResponseStream(), Encoding.UTF8)
            'instantiate new xml document to hold the google geo resulting xml
            Dim geoXml As New XmlDocument()

            geoXml.LoadXml(sr.ReadToEnd().ToString())

            'Dim TitleNode As XmlNodeList = geoXml.GetElementsByTagName("address_component")

            'Get County (administrative_area_level_2)

            _GeoCounty = geoXml.Item("/GeocodeResponse/result/address_component/[type=administrative_area_level_2]")

            _GeoCountyData = _GeoCounty.InnerXml.ToString()



            StatusLBL.Text = _GeoCountyData

            'Get Lat/Long
            _Latitude = geoXml.SelectSingleNode("/GeocodeResponse/result/geometry/location/lat")
            _Longitude = geoXml.SelectSingleNode("/GeocodeResponse/result/geometry/location/lng")
            _LatitudeValue = _Latitude.InnerText.ToString()
            _LongitudeValue = _Longitude.InnerText.ToString()
Reply all
Reply to author
Forward
0 new messages