How to reverse geocode using the Cordoba geolocation API to get the city and country?

I am creating a hybrid mobile application using the Intel App Framework for the user interface and Cordova for accessing the device’s native functions.

As part of the development, I need to get the user's location (city and country) and show it in the text box.

Using the code below, I can get the Latitude and Longitude and show it in two different text fields (with the latitude and longitude of the identifier). How to translate latitude and longitude to a city and a country.

  function Geolocation() {
                    var onSuccess = function(position) {
                        document.getElementById('latitude').value = position.coords.latitude;
                        document.getElementById('longitude').value = position.coords.longitude;                    
                    };
                    var onFail = function() {
                        navigator.notification.alert('Cannot get the location');
                    };
                    navigator.geolocation.getCurrentPosition(onSuccess, onFail, {maximumAge:0, timeout:5000, enableHighAccuracy: true});
                }  

Note. I do not use any other plugin other than Cordoba geolocation to handle location services in my application. This is a hybrid app, but I'm currently working on a version of the Android app.

+4
1

, - . Google Maps, OpenStreetMaps .

OpenStreetMaps, . JSONP:

http://nominatim.openstreetmap.org/reverse?lat=-23.5880894&lon=-46.6321951&format=json&json_callback=my_callback

, Ajax URL . :

function showCountry(lat, lon) {
    $.getJSON('//nominatim.openstreetmap.org/reverse?json_callback=?&format=json', {lat: lat, lon: lon}, function(data) {
       alert(data.address.country);
   });
}
+6

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


All Articles