【问题标题】:Azure Maps API workaround for unsupported regions不受支持区域的 Azure Maps API 解决方法
【发布时间】:2018-10-31 15:36:45
【问题描述】:

我正在使用 Azure Maps API 进行地理编码反转。有时,它有效,有时则无效。在研究过程中,我发现了一份文件-https://docs.microsoft.com/en-us/azure/azure-maps/about-azure-maps。它表示以下国家/地区目前不支持该 API-

  • 阿根廷
  • 中国
  • 印度
  • 摩洛哥
  • 巴基斯坦
  • 韩国

我正在寻找解决方法。有什么方法可以使用印度的 API?

【问题讨论】:

    标签: azure azure-maps


    【解决方案1】:

    一种选择是使用 VPN 进入受支持的区域。请注意,如果您这样做,请不要公开分享地图,因为它会显示与这些国家/地区的观点不一致的内容,并且可能会给您的公司带来一些麻烦。其中许多国家/地区可能会在 2019 年初解封。

    【讨论】:

    • 谢谢。我想出了一个解决办法。请检查我的答案。
    【解决方案2】:

    这是我想出的解决方法。

    在 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 的响应。

    【讨论】:

      猜你喜欢
      • 2023-02-20
      • 1970-01-01
      • 2021-05-20
      • 2020-10-02
      • 2021-07-04
      • 2012-10-18
      • 2016-01-06
      • 2010-12-07
      • 2014-12-13
      相关资源
      最近更新 更多