gpt4 book ai didi

c# - 从 Windows 窗体应用程序调用 Google Maps API V3 Javascript API?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:20:09 24 4
gpt4 key购买 nike

Google 有这个很好的新 Google Maps API v3这是一个“Javascript API”。

是否有可能从用 Visual C# .net 3.5 编写的 Windows 窗体应用程序调用此 API?

编辑:
目标是使用 Google map 地理编码器将地址转换为纬度/经度格式。

编辑 2:
我想使用 API 的 v3,因为它不再需要 API key 。 API key 应绑定(bind)到网络服务器,而 Windows 窗体应用则不能。

最佳答案

编辑:看起来不再需要 api key 。

您可以使用 REST APIs并解析响应 (XML/JSON/CSV)。

http://maps.google.com/maps/geo?q=State+St,+Troy,+NY&output=csv&oe=utf8&sensor=false

会输出:

200,6,42.730070,-73.690570

这是:

  • 200 - G_GEO_SUCCESS
  • 6 - 街道级别精度
  • 42.730070 - 纬度
  • -73.690570 - 经度

如果您不熟悉 System.Net API,它们会是这样的:

const string GeoCodeUrlFormat = "http://maps.google.com/maps/geo?q={0}&output=csv&oe=utf8&sensor=false";

string location = "State St, Troy, NY";
string url = String.Format(GeoCodeUrlFormat, HttpUtility.UrlEncode(location));

HttpRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
HttpResponse response = (HttpResponse)request.GetResponse(); // Can throw an exception
Stream responseStream = response.GetResponseStream();

using (StreamReader reader = new StreamReader(responseStream)
{
string firstLine = reader.ReadLine();

string[] lineParts = firstLine.Split();

GeolocationResult result = GoogleMapper.MapGeolocationResult(lineParts);

// TADA
}

显然没有错误处理,它不支持多个返回值,而且我还没有实际实现 MapGeolocationResult,但它应该能让您入门。

关于c# - 从 Windows 窗体应用程序调用 Google Maps API V3 Javascript API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1199973/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com