当全球定位系统启用时,地理定位成功是完美的。但是,当全球定位系统开通时,在离子框架上不调用移动device.Working中的地理定位误差,使用phonegap地理定位来检查是否启用。密码在这里
var locOptions = {
maximumAge : 10000,
timeout : 5000,
enableHighAccuracy : true
};
function onLocationSuccess(position) {
console.log(position);
// alert('success');
$rootScope.pos = new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);
var geocoder = new google.maps.Geocoder();
geocoder.geocode({'latLng': $rootScope.pos}, function address(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
$rootScope.currentposition = results[1].formatted_address;
console.log($rootScope.currentposition);
if($scope.switchToState=='signedIn'){
$ionicLoading.hide();
$http.get($rootScope.url +'api/price/?key=movo1026868hk738hkl')
.success(function(response) {
$rootScope.truckfare=response.datasets;
});
console.log('reached here2');
$state.go('app.home');
}
else{
$ionicLoading.hide();
$state.go('start');
}
}
}
});
}
// onError Callback receives a PositionError object
//
function onLocationError(error) {
alert("Geolocation error: #" + e.code + "\n" + e.message);
}
navigator.geolocation.getCurrentPosition(onLocationSuccess, onLocationError, locOptions);发布于 2015-07-25 20:11:00
如果GPS关闭,地理定位API将不会给出错误,因为这不是错误状态。如果它无法在您指定的时间限制内获得锁,则只会超时。
不幸的是,这是一个真正的问题。如果关闭GPS和地理定位API超时,除非重新启动整个应用程序,否则将无法使其再次工作。因此,即使您将GPS返回联机,除非重新启动应用程序,否则API也不会再次工作。
这里有个简单的解决办法。在初始化地理定位API之前,检查GPS是否联机。您可以使用这个PhoneGap/Cordova插件来做到这一点:
https://github.com/mablack/cordova-diagnostic-plugin
本质上,这个插件将解决你最初的问题+我之前提到过的问题。
https://stackoverflow.com/questions/31628841
复制相似问题