为了减少我的web表单asp.net项目中的可计费事务,我决定测试它。
我在msdn上遇到了下面的会话密钥示例。
Map.CredentialsProvider.GetCredentials(
Function(c)
Dim sessionKey As String = c.ApplicationId
'Generate a request URL for the Bing Maps REST services.
'Use the session key in the request as the Bing Maps key
Return 0
End Function)我的代码示例
private String GeocodeAddress(string address)
{ string results = "";
string key = "Bing Maps key";
GeocodeRequest geocodeRequest = new GeocodeRequest();
// Set the credentials using a valid Bing Maps key
geocodeRequest.Credentials = new GeocodeService.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;}
调试之后,我看不到b/w (应用程序id /会话键)和Bing Api键的任何区别。如何在上面的例子中获得会话密钥?
发布于 2014-10-15 14:18:29
会话键只能在与交互式地图相同的页面上使用。不允许在页之间传递会话密钥。假设您有一个AJAX按钮或在服务器上处理一些代码并将其返回到与映射相同的页面,那么就可以了。
第一段代码看起来像是要在.NET中生成会话密钥,这只有在使用Silverlight或WPF的地方才有可能。我假设您没有在服务器上使用Bing Maps WPF控件,因为这实际上违反了使用条款。如果您使用Silverlight,则不需要将密钥传递到服务器端。
因此,假设您从Bing Maps v7控件在v7中生成一个密钥,并将其传递给服务器上的AJAX按钮处理程序。如果是这样的话,那就没关系。
在您的代码中,您似乎使用的是非常老的遗留SOAP服务,这是不建议使用的。事实上,我在四五年前就不再推荐他们了。这些文件几年前就离线了。您应该使用Bing Maps REST服务,这些服务更快、更准确,并且具有更多的功能。您可以在这里找到关于如何在.NET中使用它们的文档:http://msdn.microsoft.com/en-us/library/jj819168.aspx
另外,以下是关于使用REST服务的一些技巧:http://blogs.bing.com/maps/2013/02/14/bing-maps-rest-service-tips-tricks/
ApplicationId和会话密钥是相同的。SOAP服务太老了,曾经有一个不同的名称。
你不会马上在报告中看到任何不同之处。报告在所有服务器/数据中心之间同步可能需要长达一周的时间,因为这是一项低优先级的工作,需要大量的数据。
如果您的应用程序有良好的流量,您可能会有更多的非计费交易比可计费交易,这可能会导致您的帐户被标记,调查,并可能被封锁。
您应该做的是提前对您的地址进行地理编码,并存储坐标。这是大多数应用程序处理这种场景的方式。唯一需要动态地编码的时间是,如果您有一个搜索框以供用户输入,所有其他内容都应该提前进行地理编码以提高性能。
https://stackoverflow.com/questions/26371841
复制相似问题