2013-05-22 25 views
0

我使用以下服務引用得到緯度位置的細節和longnitude的Windows Phone ReverseGeocoding從中獲取地址緯度和長

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找不到。

幫助我解決問題,並告訴我這是找到位置詳細信息的最佳方法。

回答

1

在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(); 
+0

我嘗試過,但有些時候,它給它的結果非常快,有時需要很長時間才能獲取結果 –

+0

請注意,您的方法和我的方法都會查詢外部服務器以獲取結果。他們依賴於網絡連接。 – anderZubi

+0

是的,你是對的,下面的方法需要很長時間Geoposition currentPosition =等待geolocator.GetGeopositionAsync(TimeSpan.FromMinutes(1),TimeSpan.FromSeconds(10));給緯度和長度是否有任何替代方法來查找設備當前位置 –