[c#]Windows Phone ReverseGeocoding 从 Lat 和长获取地址

标签: windows C#
发布时间: 2013/12/7 14:43:05
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

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

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

我上面的 URL 添加到我的服务引用类并尝试获取的位置详细信息通过调用以下方法

 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。

帮我解决 problem.and 还告诉我这是最佳的方式来找到位置的详细信息。

解决方法 1:

在 Windows Phone 8 您有内置的反向地理编码,而无需添加服务引用到 Bing Maps 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();
官方微信
官方QQ群
31647020