使用Nominatim API进行反向地理编码无效

时间:2018-07-24 18:11:29

标签: c# openstreetmap geocoding nominatim

我需要根据一对latlon坐标找出城市的名称

我正在使用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可以很好地工作并且查询可以在浏览器上工作

1 个答案:

答案 0 :(得分:1)

它总是失败还是只是有时候?

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