2016-06-01 163 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

相关问题