我试图调用谷歌地图地理编码和我跟随在他们的网页上的例子,试图将其应用到在这个例子中挖掘如何读取返回的XML值映射
http://code.google.com/apis/maps/documentation/geocoding/index.html
, Geocoding API请求上面显示的“1600 Amphitheatre Parkway,Mountain View,CA”的 相同查询的xml响应: http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true_or_false 此请求返回的XML如下所示。
我现在想运行一个URL像这样在我的C#WinForms应用程序
string url = "http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true_or_false";
WebRequest req = HttpWebRequest.Create(url);
WebResponse res = req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream());
try
{
Match coord = Regex.Match(sr.ReadToEnd(), "<coordinates>.*</coordinates>");
var b = coord.Value.Substring(13, coord.Length - 27);
}
finally
{
sr.Close();
}
但是它似乎没有被返回任何东西,因此我的变种B线给出了一个索引出界失误。任何人都可以指出我在正确的方向,至少让示例工作,所以我可以将逻辑应用到我自己的应用程序?
感谢
+1通过阅读文档求解 – Alain
我想我第一次尝试API时错过了传感器参数。 –
常识 - 我明显缺乏。对不起 - 你在代码中沉浸在代码中,作为一个初学者,你忘记退后一步,看看在你面前的是什么 - 谢谢 – simon