代码之家  ›  专栏  ›  技术社区  ›  Souvik Ghosh

不支持区域的azure地图api解决方案

  •  0
  • Souvik Ghosh  · 技术社区  · 7 年前

    我正在使用azure maps api来进行地理代码反转。有时有效,有时无效。我在研究时发现了一份文件- https://docs.microsoft.com/en-us/azure/azure-maps/about-azure-maps . 它说,目前不支持以下国家的API-

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

    我在找解决办法。有什么办法可以使用印度的API吗?

    2 回复  |  直到 7 年前
        1
  •  1
  •   rbrundritt    7 年前

    一种选择是使用VPN进入受支持的区域。注意,如果你这样做,不要公开分享地图,因为它会显示那些不符合这些国家观点的东西,可能会给你的公司带来麻烦。其中许多国家可能会在2019年初解除封锁。

        2
  •  0
  •   Souvik Ghosh    7 年前

    这是我想出来的解决办法。

    在azure中创建一个函数应用程序,并对azure地图api进行http调用。确保应用程序托管在允许使用azure maps 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.");
    }
    

    函数应用程序应该以latitdue和longitude作为参数并进行http调用。

    https://<function_app>.azurewebsites.net/api/GetLocation?code=1/<function_secret_key>&lattlong=13.097045900000001,77.59058569999999
    

    函数应用程序成功返回来自azure映射api的响应。

    enter image description here

    推荐文章