C# Windows Phone反向编码以从Lat和Long获取地址
我使用以下服务参考从latitude和longnitude获取位置详细信息 我将上面的URL添加到我的服务引用类中,并尝试通过调用下面的方法来获取位置详细信息C# Windows Phone反向编码以从Lat和Long获取地址,c#,windows-phone-8,reverse-geocoding,service-reference,C#,Windows Phone 8,Reverse Geocoding,Service Reference,我使用以下服务参考从latitude和longnitude获取位置详细信息 我将上面的URL添加到我的服务引用类中,并尝试通过调用下面的方法来获取位置详细信息 public void reverse() { string Results = ""; try { // Set a Bing Maps key before making a request
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;
}
但我收到了以下错误消息
请帮助我解决此问题。并告诉我这是查找位置详细信息的最佳方法。在Windows Phone 8中,您具有用于反向地理编码的内置API,无需向Bing地图添加服务引用:
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();
列出位置;
ReverseGeocodeQuery=新建ReverseGeocodeQuery();
query.geocordinate=新的geocordinate(47.608,-122.337);
query.QueryCompleted+=(s,e)=>
{
如果(e.Error==null&&e.Result.Count>0)
{
位置=e。结果为列表;
//对返回的位置执行任何操作。
//例如,MapAddress address=位置[0]。Information.address;
}
};
query.QueryAsync();
我尝试过,但有时结果非常快,有时需要很长时间才能获取结果,您和我的方法都需要查询外部服务器以获得结果。它们取决于网络连接。是的,您是对的,下面的方法需要很长时间Geoposition currentPosition=Wait GeopLocator.GetGeopositionAsync(TimeSpan.FromMinutes(1),TimeSpan.FromSeconds(10));为了提供纬度和长度,是否有其他方法来查找设备当前位置,但是,获取当前位置或执行反向地理代码查询需要时间?使用Geoposition currentPosition=Wait Geoplocator.GetGeopositionAsync(TimeSpan.FromMinutes(1)获取当前位置时间跨度从秒(10)开始;