Javascript 如何使用Cordova地理定位API进行反向地理编码以获取城市和国家?

Javascript 如何使用Cordova地理定位API进行反向地理编码以获取城市和国家?,javascript,cordova,geolocation,hybrid-mobile-app,reverse-geocoding,Javascript,Cordova,Geolocation,Hybrid Mobile App,Reverse Geocoding,我正在构建一个混合移动应用程序,使用Intel的用户界面应用程序框架和Cordova来访问本机设备功能 作为开发的一部分,我需要获得用户的位置(城市和国家),并在文本框中显示 通过使用下面的代码,我能够获得纬度和经度,并将其显示在两个不同的文本框中(分别使用ID Latitude和Longitude)。如何将纬度和经度转换为城市和国家 function Geolocation() { var onSuccess = function(position)

我正在构建一个混合移动应用程序,使用Intel的用户界面应用程序框架和Cordova来访问本机设备功能

作为开发的一部分,我需要获得用户的位置(城市和国家),并在文本框中显示

通过使用下面的代码,我能够获得纬度和经度,并将其显示在两个不同的文本框中(分别使用ID Latitude和Longitude)。如何将纬度和经度转换为城市和国家

  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});
                }  
注意-除了Cordova的Geolocation,我没有使用任何其他插件来处理我的应用程序中的定位服务。这是一个混合应用程序,但目前我正在开发Android版本的应用程序。

这被称为反向地理编码。有很多服务可以做到这一点,例如谷歌地图、OpenStreetMaps等

我喜欢OpenStreetMaps,因为它非常容易操作。只是一个JSONP回调:

因此,您可以对该URL发出Ajax请求,并获得所需的值。例如:

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

首先,谢谢你的回答。我应该和Cordova一起使用吗?我无法在我的Windows phone应用程序中使用它。
函数showCountry(lat,lon){$.post('http://nominatim.openstreetmap.org/reverse/“,{格式:'json',lat:lat,lon:lon},函数(data){alert(data.address.country);});}
不过我可以在浏览器中查看json。