2

我正在用 C# 编写一个 asp.net 程序,它应该获取一个地址,使用谷歌地理编码 Web 服务返回一个 XML 页面,然后在 XML 页面上找到该地址的经度和纬度。如果我已经构建了查询字符串(例如http://maps.googleapis.com/maps/api/geocode/xml?address=1000+Fifth+Avenue,+New+York,+NY&sensor=false),我将如何继续发送该查询并返回 C# 中的返回 XML 页面?

4

1 回答 1

6

做这个;

XmlDocument xDoc = new XmlDocument();
xDoc.Load("http://maps.googleapis.com/maps/api/geocode/xml?address=1000+Fifth+Avenue,+New+York,+NY&sensor=false");

这将为您提供您的 XmlDocument,然后您可以根据需要进行处理。

所以如果你想获得经纬度,你可以使用XPath

var lat = xDoc.SelectSingleNode("/GeocodeResponse/result/geometry/location/lat").InnerText;
var longitude  = xDoc.SelectSingleNode("/GeocodeResponse/result/geometry/location/lng").InnerText;
于 2012-08-29T15:58:47.363 回答