Windows Phone反向地理编码从纬度和经度获取地址 [英] Windows Phone ReverseGeocoding to get Address from Lat and Long
问题描述
我正在使用以下服务参考从纬度和经度获取位置详细信息
i am using the following service reference to get location details from latitude and longnitude
http://dev.virtualearth.net/webservices/v1/geocodeservice/geocodeservice.svc
我将上述 URL 添加到我的服务引用类中,并尝试通过调用以下方法获取位置详细信息
i added the above URL to my Service reference class and try to get the location details by calling the below method
public void reverse()
{
string Results = "";
try
{
// Set a Bing Maps key before making a request
string key = "Bing Maps Key";
ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();
// Set the credentials using a valid Bing Maps key
reverseGeocodeRequest.Credentials = new GeoCodeService.Credentials();
reverseGeocodeRequest.Credentials.ApplicationId = key;
// Set the point to use to find a matching address
GeoCodeService.Location point = new GeoCodeService.Location();
point.Latitude = 47.608;
point.Longitude = -122.337;
reverseGeocodeRequest.Location = point;
// Make the reverse geocode request
GeocodeServiceClient geocodeService = new GeocodeServiceClient();
**GeocodeResponse geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest);**
}
catch (Exception ex)
{
Results = "An exception occurred: " + ex.Message;
}
但我收到以下错误消息
GeoCodeService.GeoCodeServiceClient 不包含 ReverseGeocode 的定义,也没有扩展方法
GeoCodeService.GeoCodeServiceClient does not contain a definition for ReverseGeocode and no extension method
找不到 GeoCodeService.GeoCodeServiceClient.
GeoCodeService.GeoCodeServiceClient could not be found.
帮助我解决问题.并告诉我这是查找位置详细信息的最佳方法.
help me in solving the problem.and also tell me is this a best way to find location details .
推荐答案
在 Windows Phone 8 中,您具有用于反向地理编码的内置 API,而无需向 Bing 地图添加服务引用:
In Windows Phone 8 you have built-in API for reverse geocoding, without the need of adding a Service Reference to Bing Maps:
List<MapLocation> locations;
ReverseGeocodeQuery query = new ReverseGeocodeQuery();
query.GeoCoordinate = new GeoCoordinate(47.608, -122.337);
query.QueryCompleted += (s, e) =>
{
if (e.Error == null && e.Result.Count > 0)
{
locations = e.Result as List<MapLocation>;
// Do whatever you want with returned locations.
// e.g. MapAddress address = locations[0].Information.Address;
}
};
query.QueryAsync();
这篇关于Windows Phone反向地理编码从纬度和经度获取地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!