【问题标题】:Reverse geocoding using Nominatim API doesn't work使用 Nominatim API 的反向地理编码不起作用
【发布时间】:2019-01-01 10:59:57
【问题描述】:

给定一对lat,lon坐标,我需要找出城市的名称

我正在使用 Nominatim API https://wiki.openstreetmap.org/wiki/Nominatim

这是一个示例查询:

https://nominatim.openstreetmap.org/reverse?format=xml&lat=40&lon=30&zoom=18&addressdetails=1

它可以在浏览器中运行,但是它在这个 C# 代码中失败了:

    ServicePointManager.Expect100Continue = true;
    ServicePointManager.DefaultConnectionLimit = 9999;
    ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;

    var url = "https://nominatim.openstreetmap.org/reverse?format=xml&lat=40&lon=30&zoom=18&addressdetails=1";
    var request = (HttpWebRequest)WebRequest.Create(url);
    var response = (HttpWebResponse)request.GetResponse();
    var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

我得到以下异常:

底层连接已关闭:连接已关闭 没想到。

不知道为什么上面的代码在其他 API 上工作得很好,而查询在浏览器上也能工作

【问题讨论】:

    标签: c# openstreetmap geocoding nominatim


    【解决方案1】:

    它总是失败还是偶尔失败?

    目前,一些 OSM 服务器已从伦敦移至阿姆斯特丹。 API 和可能的其他服务(例如 Nominatim)在备份硬件上运行,直到主服务器再次启动。这会降低性能,也可能导致零星的问题。见https://lists.openstreetmap.org/pipermail/talk/2018-July/081009.html。您可以在https://twitter.com/osm_tech 上查看当前状态。

    【讨论】:

    【解决方案2】:

    对我来说,我正在使用 angular 进行测试

    http://nominatim.openstreetmap.org/reverse?format=json&lon= lon &lat= lag
    

    为本地主机工作,但上线后不再工作。 只需更改为

    https://nominatim.openstreetmap.org/reverse?format=json&lon= lon &lat= lag
    

    有效。

    http -> https
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多