Mar*_*arc 3 .net javascript c# winforms
Google推出了这款精美的全新Google Maps API v3,它是一款"Javascript API".
是否有可能从用Visual C#.net 3.5编写的Windows窗体应用程序中调用此API?
编辑:
目标是使用Google Maps Geocoder将地址转换为纬度/经常格式.
编辑2:
我想使用API的v3,因为它不再需要API密钥.API密钥应绑定到Web服务器,而Windows Forms应用程序则不然.
编辑:看起来不再需要api密钥.
您可以使用REST API并解析响应(XML/JSON/CSV).
http://maps.google.com/maps/geo?q=State+St,+Troy,+NY&output=csv&oe=utf8&sensor=false
Run Code Online (Sandbox Code Playgroud)
输出:
200,6,42.730070,-73.690570
Run Code Online (Sandbox Code Playgroud)
这是:
如果您不熟悉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
}
Run Code Online (Sandbox Code Playgroud)
显然没有错误处理,它不支持多个返回值,我实际上没有实现MapGeolocationResult,但它应该给你一个开始.
| 归档时间: |
|
| 查看次数: |
13378 次 |
| 最近记录: |