Google Maps API has upgraded their geocoding service. The old style had each data element in a unique node, so I was reading each node using SelectSingleNode. Now, the node names are all the same, so my VB.net program is not working accurately, except on
the lat/long parameters because those are still unique.
Here is the link to an address and how the API responds: http://maps.googleapis.com/maps/api/geocode/xml?address=1210%20cassat%20av,%20jacksonville,%20fl,%20USA&sensor=true
and here is my code:
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()
data1025
Member
11 Points
32 Posts
Reading XML data from Google GeoCode (Maps) Service v3
Apr 09, 2011 02:57 PM|LINK
Google Maps API has upgraded their geocoding service. The old style had each data element in a unique node, so I was reading each node using SelectSingleNode. Now, the node names are all the same, so my VB.net program is not working accurately, except on the lat/long parameters because those are still unique.
Here is the link to an address and how the API responds: http://maps.googleapis.com/maps/api/geocode/xml?address=1210%20cassat%20av,%20jacksonville,%20fl,%20USA&sensor=true
and here is my code:
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()Martin_Honne...
Star
14481 Points
2006 Posts
MVP
Re: Reading XML data from Google GeoCode (Maps) Service v3
Apr 10, 2011 10:43 AM|LINK
Are you simply struggling with the XPath syntax? Try
string s = geoXml.SelectSingleNode("/GeocodeResponse/result/address_component[type = 'administrative_area_level_2']/long_name").InnerText;
My blog
data1025
Member
11 Points
32 Posts
Re: Reading XML data from Google GeoCode (Maps) Service v3
Jun 13, 2011 03:02 AM|LINK