【发布时间】:2014-10-14 23:02:44
【问题描述】:
为了减少我的 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;
}
调试后,我看不出黑白(应用程序 ID/会话密钥)和 Bing Api 密钥有任何区别。如何在上面的示例中获取 sessionkey?
【问题讨论】:
标签: c# asp.net map bing-maps bing-api