Simple reverse geocoding using Nominatim

I am developing an online mapping application using OpenLayers + OpenStreetMaps.

I need help implementing a simple reverse geocoding function in javascript (or php) that takes latitude and longitude and returns an address.

I would like to work with Nominatim, if possible. I DO NOT want to use Google, Bing or CloudMade or other proprietary solutions.

this link returns a reasonable answer, and I used simple_html_dom.php to break up the result, but this is kind of an ugly solution.

<?php include('simple_html_dom.php'); $url = "http://nominatim.openstreetmap.org/reverse?format=xml&lat=-23.56320001&lon=-46.66140002&zoom=27&addressdetails=1"; $html = file_get_html($url); foreach ($html->find('road') as $element ) { echo $element; } ?> 

any suggestions for a more elegant solution?

NOTE: as of October 2015, the request must contain a valid letter to "ensure sufficient identification of your application."

Without email, the return code will NOT be in xml or json format, but rather like error 509 "Bandwidth exceeded" , try using the html_dom library for cleaning.

 $url = "http://nominatim.openstreetmap.org/ reverse?email=myemail@myserver.com &format=xml&lat=-23.56320001&lon=-46.66140002&zoom=27&addressdetails=1"; 
+4
source share
2 answers

You can request nominatim in JSON format and pass a callback name so that the response is: callback(json) .

Take a look at the document: http://wiki.openstreetmap.org/wiki/Nominatim

And this is a minimal use case: http://jsfiddle.net/GWL7A/14/

+6
source

I have been implementing the tonio solution for 4 years. Although it is well implemented, and I recommend it as such (even approving it as the correct answer), but it became clear that the answer is incomplete.

Depending on how your requests are implemented, you may run into problems with the servers, which can even lead to a denial of service.

Please keep in mind that if you use the Nominatim community servers as suggested in his answer, the best thing is:

+1
source

Source: https://habr.com/ru/post/1416484/


All Articles