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";
source share