我试图使用地理编码api
使用此代码将地址转换为经度和纬度protected void Button1_Click(object sender, EventArgs e)
{
IGeocoder geocoder = new GoogleGeocoder() { };
Address[] addresses = geocoder.Geocode("#65/1 bangalore").ToArray();
foreach (Address adrs in addresses)
{
Response.Write("address:"+adrs);
}
}
我得到的答案是更详细的地址而不是经度和纬度。例如我得到的代码
address:Hari Om Trust Tapovana, 1, Bangalore, Karnataka 562123, India
有人请告诉我我必须做哪些修改才能获得经度和纬度?
googlegeocoder的代码是
#region Assembly Geocoding.dll, v3.1.0.0
// C:\Users\Admin\Documents\Visual Studio 2012\WebSites\learn1\Bin\Geocoding.dll
#endregion
using Geocoding;
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
namespace Geocoding.Google
{
public class GoogleGeocoder : IGeocoder, IAsyncGeocoder
{
public GoogleGeocoder();
public string ApiKey { get; set; }
public Bounds BoundsBias { get; set; }
public BusinessKey BusinessKey { get; set; }
public string Language { get; set; }
public WebProxy Proxy { get; set; }
public string RegionBias { get; set; }
public string ServiceUrl { get; }
public IEnumerable<GoogleAddress> Geocode(string address);
public Task<IEnumerable<GoogleAddress>> GeocodeAsync(string address);
public Task<IEnumerable<GoogleAddress>> GeocodeAsync(string address, CancellationToken cancellationToken);
public IEnumerable<GoogleAddress> ReverseGeocode(Location location);
public IEnumerable<GoogleAddress> ReverseGeocode(double latitude, double longitude);
public Task<IEnumerable<GoogleAddress>> ReverseGeocodeAsync(double latitude, double longitude);
public Task<IEnumerable<GoogleAddress>> ReverseGeocodeAsync(double latitude, double longitude, CancellationToken cancellationToken);
protected class RequestState
{
public readonly CancellationToken? cancellationToken;
public readonly HttpWebRequest request;
public RequestState(HttpWebRequest request, CancellationToken? cancellationToken);
}
}
}
答案 0 :(得分:3)
啊......事实很简单:
protected void Button1_Click(object sender, EventArgs e)
{
IGeocoder geocoder = new GoogleGeocoder() { };
Address[] addresses = geocoder.Geocode("#65/1 bangalore").ToArray();
foreach (Address adrs in addresses)
{
Response.Write("address:"+adrs.Coordinates);
}
}
干杯
编辑:您只看到街道地址的原因是因为您的循环默认调用了Address.ToString()。
答案 1 :(得分:0)
参考: 谷歌有一个地理编码API,对于他们拥有谷歌地图数据的大多数地方来说似乎都能很好地运作。
http://googlemapsapi.blogspot.com/2006/06/geocoding-at-last.html
他们提供在线地理编码(通过JavaScript):
http://code.google.com/apis/maps/documentation/services.html#Geocoding
或后端地理编码(通过HTTP请求):
http://code.google.com/apis/maps/documentation/services.html#Geocoding_Direct
数据通常与Google地图本身使用的数据相同。 (请注意,有一些例外情况,例如英国或以色列,其数据来自不同的来源,质量略有下降)
答案 2 :(得分:0)