这是我想出的解决方法。
在 Azure 中创建一个函数应用并对 Azure 地图 API 进行 Http 调用。确保应用托管在允许使用 Azure 地图 API 的区域(例如美国中部)。
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using System.Net.Http;
public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
string lattlong = req.Query["lattlong"];
HttpClient httpClient = new HttpClient();
string location = httpClient.GetStringAsync("https://atlas.microsoft.com/search/address/reverse/json?api-version=1.0&subscription-key=<secret_key>&query=" + lattlong).Result;
dynamic data = Newtonsoft.Json.Linq.JObject.Parse(location);
return lattlong != null
? (ActionResult)new OkObjectResult(data.addresses[0].address.municipality + ", " + data.addresses[0].address.country)
: new BadRequestObjectResult("Failed to get location.");
}
函数应用应以经纬度为参数,进行Http调用。
https://<function_app>.azurewebsites.net/api/GetLocation?code=1/<function_secret_key>&lattlong=13.097045900000001,77.59058569999999
函数应用成功返回来自 Azure Maps API 的响应。