I have Longitude and Latitude, I would like to connect to Geocoding or Nominatim and get the address of these Lat and Lon.
I want to do it in OpenLayers 3 using OSM.
With help from @ThomasG77, I implemented ReverseGeocoding in my code with this function:
function simpleReverseGeocoding(lon, lat) {
fetch('http://nominatim.openstreetmap.org/reverse?format=json&lon=' + lon + '&lat=' + lat).then(function(response) {
console.log(response.json());
return response.json();
}).then(function(json) {
return json.display_name;
})
}
But the answer of the JSON is:
Promise { <state>: "pending" }
When I show the address in my console:
console.log('http://nominatim.openstreetmap.org/reverse?format=json&lon=' + lon + '&lat=' + lat);
The address that it send is Kenia, or "Unable to Geocode"
Obviously, console.log(json.display_name); is undefined.
Do I have to know something about headers or something similar?
Best Answer
Just use the Nominatim reverse geocoding API.
After, it's mainly about knowing HTML and JavaScript.
I've done a simple demo for reverse geocoding using OpenLayers. You can look at the code on this GIST