0
使用bing map API,我可以在服务器端调用并获取特定城市的lat/long吗?使用bing map API,我可以打一个服务器端的电话,并获得一个给定城市的纬度/经度?
我可以在客户端使用JavaScript做到这一点,但在这种情况下我需要更强大的功能,并且希望使用服务器端。
使用bing map API,我可以在服务器端调用并获取特定城市的lat/long吗?使用bing map API,我可以打一个服务器端的电话,并获得一个给定城市的纬度/经度?
我可以在客户端使用JavaScript做到这一点,但在这种情况下我需要更强大的功能,并且希望使用服务器端。
发布此所以它的存在,并且更容易找到答案给大家:
使用Bing Maps SOAP服务API(http://msdn.microsoft.com/en-us/library/cc980922.aspx)。它是一种实现大多数Bing Maps API并提供静态地图的公共Web服务(对不起,用户没有交互性)。从提供微软SDK(略作修改:添加服务引用到项目后,运行此代码:
私人GeocodeResponse GeocodeAddress(字符串地址) { GeocodeRequest geocodeRequest =新GeocodeRequest();
// Set the credentials using a valid Bing Maps key
geocodeRequest.Credentials = new GeocodeService.Credentials();
geocodeRequest.Credentials.ApplicationId = BingMapsAPIKey;
// Set the full address query
geocodeRequest.Query = address;
// Set the options to only return high confidence results
ConfidenceFilter[] filters = new ConfidenceFilter[1];
filters[0] = new ConfidenceFilter();
filters[0].MinimumConfidence = GeocodeService.Confidence.High;
// Add the filters to the options
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);
return geocodeResponse;
}
,您可以使用以下代码片段检查您的返回值:
result.Locations[0].Latitude.ToString();
result.Locations[0].Longitude.ToString();