自从google 退出中国之后,很多的不方便.
地图勉强能用
网上有些api都是要收费的,而且收费比较多.
原来一直用必应地图提供的接口
GeocodeRequest geocodeRequest = new GeocodeRequest();
报错 the service method is not found
看了官方的列子也是这样的.
google地图没有http接口更新.网页的对请求限制100次/天
我们系统每天更新经纬度数据比较多,每天得更新好几万的数据.
下面是google地图计算经纬度接口js版本的,需要通过ajax 单条调用.
function GetGpsGoogle(address,obj) {
$.ajax({
type: "get",
dataType: "json",
async: false,
url: "http://maps.google.cn/maps/api/geocode/json?address=" + address + "",
success: function (data) {
if (data.status == 'OK') {
var lat = data.results[0].geometry.location.lat;
var lng = data.results[0].geometry.location.lng;
//更新业务数据
}
}
});
}
必应地图的接口
private void MakeGeocodeRequest()
{
string Results = "";
try
{
// Set a Bing Maps key before making a request
string key = "9hOiCZ9CeqcrrtLulix6~vW9_U20gmnMkdIBj-HwxGw~AuMx8W3CzxTLBhR6Evg9le2-p2sPZJcjZA1taqoQSjHjx1v2TXpdUyfE1pcA9sUP";
GeocodeRequest geocodeRequest = new GeocodeRequest();
// Set the credentials using a valid Bing Maps Key
geocodeRequest.Credentials = new Credentials();
geocodeRequest.Credentials.ApplicationId = key;
// Set the full address query
geocodeRequest.Query = "1 Microsoft Way, Redmond, WA";
// Set the options to only return high confidence results
ConfidenceFilter[] filters = new ConfidenceFilter[1];
filters[0] = new ConfidenceFilter();
filters[0].MinimumConfidence = Confidence.High;
GeocodeOptions geocodeOptions = new GeocodeOptions();
geocodeOptions.Filters = filters;
geocodeRequest.Options = geocodeOptions;
// Make the geocode request
GeocodeServiceClient geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest);
Results = geocodeResponse.Results[0].DisplayName;
}
catch (Exception ex)
{
Results = "An exception occurred: " + ex.Message;
}
}
现在报错,不知道谁有解决方案吗,这个接口一个秘钥能更新10万次.就是不能访问了.
最后有找了一个接口就是mapbox地图.
每分钟更新600次.这个量算好了.就是接口响应速度有点慢.
string GetPost = string.Format("https://api.mapbox.com/geocoding/v5/mapbox.places/{0}.json?access_token='你的秘钥'", address);
getStr = Command.HttpHelper.Get_Http(GetPost);
VO.BoxMap.BoxMapGpsVO model = Command.JsonHelper.ParseFormJson<VO.BoxMap.BoxMapGpsVO>(getStr);
if (model != null)
{
if (model.features != null && model.features.Length>0)
{
latitude = model.features[0].center[0].ToString();
longitude = model.features[0].center[1].ToString();
}
}
走的是httpget请求,得到结果最后反序列化,key就不公开了,需要的可以联系我,或者找到原文来源.
这是计算国外地图经纬度的几种方式,现在mapbox最好用,google地图最精准.