要解决“Bing Maps REST服务工具包 - 在委托外访问值”的问题,您可以按照以下步骤进行操作:
using System;
using System.Threading.Tasks;
using BingMapsRESTToolkit;
public static async Task GetLocationDataAsync(string location)
{
// 创建一个地理编码请求
var request = new GeocodeRequest()
{
Query = location,
IncludeIso2 = true,
IncludeNeighborhood = true,
MaxResults = 1,
BingMapsKey = "YourBingMapsKey"
};
// 发送请求并获取响应
var response = await request.Execute();
// 获取结果并返回
if (response != null && response.ResourceSets != null && response.ResourceSets.Length > 0 &&
response.ResourceSets[0].Resources != null && response.ResourceSets[0].Resources.Length > 0)
{
var locationResult = response.ResourceSets[0].Resources[0] as Location;
return locationResult.Point.Coordinates[0] + ", " + locationResult.Point.Coordinates[1];
}
return null;
}
请确保将 "YourBingMapsKey" 替换为您自己的Bing Maps API密钥。
var location = "Seattle, WA";
var locationData = await GetLocationDataAsync(location);
Console.WriteLine("Location: " + locationData);
这样,您就可以使用Bing Maps REST服务工具包在委托外访问地理位置数据了。