2016-06-01 164 views
0

我使用Bing Maps,SOAP,c#.net。我想實現GeocodeAddress(),但類型或命名空間名稱'Confidence'不會在命名空間中:名稱空間中不存在類型或名稱空間名稱'置信'

private String GeocodeAddress(string address) 
     { 
      string results = ""; 
      string key = "insert your Bing Maps key here"; 
      GeocodeRequest geocodeRequest = new GeocodeRequest(); 

      // Set the credentials using a valid Bing Maps key 
      geocodeRequest.Credentials = new    DevExpress.Map.BingServices.Credentials(); 
      geocodeRequest.Credentials.ApplicationId = key; 

      // Set the full address query 
      geocodeRequest.Query = address; 

      // Set the options to only return high confidence results 
      ConfidenceFilter[] filters = new ConfidenceFilter[1]; 
      filters[0] = new ConfidenceFilter(); 

      filters[0].MinimumConfidence = GeocodeService.Confidence.High; 

      // Add the filters to the options 
      GeocodeOptions geocodeOptions = new GeocodeOptions(); 
      geocodeOptions.Filters = filters; 
      geocodeRequest.Options = geocodeOptions; 

      // Make the geocode request 
      GeocodeServiceClient geocodeService = new  GeocodeServiceClient(); 
      GeocodeResponse geocodeResponse =   geocodeService.Geocode(geocodeRequest); 

      if (geocodeResponse.Results.Length > 0) 
       results = String.Format("Latitude: {0}\nLongitude: {1}", 
        geocodeResponse.Results[0].Locations[0].Latitude, 
        geocodeResponse.Results[0].Locations[0].Longitude); 
      else 
       results = "No Results Found"; 

      return results; 
     } 
+0

代碼看起來與代碼[此處](乍一看)完全相同(https://msdn.microsoft.com/zh-cn/library/dd221354.aspx)。你有什麼改變嗎? –

+0

我只改變這個: geocodeRequest.Credentials = new DevExpress.Map.BingServices.Credentials(); @Damien_The_Unbeliever – ccorcoy

+0

當你添加服務引用時,你確定你給服務的名字是「GeocodeService」嗎?即該名稱的第一部分是您提供給服務引用的任何名稱,並且很容易意外地接受'ServiceReference1'作爲引用的名稱。 –

回答

0

看起來你正在使用Bing地圖很老的SOAP服務。 Bing地圖團隊停止推薦使用6年前的那些地圖。 Bing Maps REST服務速度更快,功能更多且定期更新。在REST服務文檔可以在這裏找到:https://msdn.microsoft.com/en-us/library/ff701713.aspx

有關於如何在.NET這裏使用REST服務文檔:https://msdn.microsoft.com/en-us/library/jj819168.aspx

我還建議在這裏檢查出的最佳實踐文件:https://msdn.microsoft.com/en-us/library/dn894107.aspx

相關問題