Windows Phone ReverseGeocoding从Lat和Long中获取地址

本文关键字:Long 获取 地址 Lat Phone ReverseGeocoding Windows | 更新日期: 2023-09-27 18:14:51

我使用以下服务引用从纬度和经度获取位置详细信息

http://dev.virtualearth.net/webservices/v1/geocodeservice/geocodeservice.svc

我将上面的URL添加到我的Service引用类中,并尝试通过调用下面的方法

来获取位置详细信息
 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;
           }

但我得到以下错误信息

  1. GeoCodeService。GeoCodeServiceClient不包含ReverseGeocode的定义,也没有扩展方法

  2. GeoCodeService。无法找到GeoCodeServiceClient .

帮助我解决这个问题。请告诉我这是查找位置信息的最好方法吗

Windows Phone ReverseGeocoding从Lat和Long中获取地址

在Windows Phone 8中,您有内置的API用于反向地理编码,而无需添加到必应地图的服务引用:

        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();