Android “错误”;无法启动地理定位服务代码:2“;在安卓手机上

Android “错误”;无法启动地理定位服务代码:2“;在安卓手机上,android,ibm-mobilefirst,w3c-geolocation,Android,Ibm Mobilefirst,W3c Geolocation,我是IBM Worklight的新手。在使用谷歌地图时,我需要使用gps获取设备的当前位置 我在emulator上没有收到任何错误,但在手机中收到以下警报 {“消息”:。“启动地理定位服务失败”,“代码”:2} 下面的代码正在使用 function alertGeo() { navigator.geolocation.getCurrentPosition(onSuccess, onError); function onSuccess(position) { cod

我是IBM Worklight的新手。在使用谷歌地图时,我需要使用gps获取设备的当前位置

我在emulator上没有收到任何错误,但在手机中收到以下警报

{“消息”:。“启动地理定位服务失败”,“代码”:2}

下面的代码正在使用

function alertGeo() {
    navigator.geolocation.getCurrentPosition(onSuccess, onError);
    function onSuccess(position) {
        codeLatLng(position.coords.latitude,position.coords.longitude);
    }
    function onError(error) {
        alert(JSON.stringify(error));
    }
}


function codeLatLng(lat,lng) {

      var latlng = new google.maps.LatLng(lat, lng);
      geocoder = new google.maps.Geocoder();
      geocoder.geocode({'latLng': latlng}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          if (results[1]) {
           alert("Address: " + results[1].formatted_address);

          } else {
            alert('No results found');
          }
        } else {
          alert('Geocoder failed due to: ' + status);
        }
      });
    }

确保在android\native\AndroidManifest.xml中设置了以下权限:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
navigator.geolocation.getCurrentPosition(onSuccess, onError, {enableHighAccuracy: true});