【发布时间】:2011-09-19 17:40:27
【问题描述】:
我正在尝试调用谷歌地图地理编码,并按照他们网页上的示例尝试将其应用于我的地图
http://code.google.com/apis/maps/documentation/geocoding/index.html
在本例中,Geocoding API 为 上面显示的相同查询“1600 Amphitheatre Parkway, Mountain 加利福尼亚州查看”: http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=true_or_false 该请求返回的 XML 如下所示。
现在我正在尝试在我的 c# winforms 应用程序中运行这样的 url
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();
}
但是它似乎没有返回任何东西,因此我的 var b 行给出了一个索引越界错误。谁能指出我正确的方向,至少让示例能够工作,这样我就可以将逻辑应用到我自己的应用程序中?
谢谢
【问题讨论】:
标签: c# winforms google-maps google-maps-api-3 httpwebrequest