app.controller('dashboard', function($scope){
$scope.getPosition = function(position){
$scope.acc = position.coords;
$scope.lat = position.coords.latitude;
$scope.lng = position.coords.longitude;
$scope.$apply();
};
$scope.getPositionErr = function(error){
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
};
navigator.geolocation.getCurrentPosition($scope.getPosition, $scope.getPositionErr, {maximumAge: 0, timeout: 6000, enableHighAccuracy:false});
});
I am using Angular JS and Cordova for an Android app. This code is working fine on desktop but not on Nexus 4 with Lollipop. Also controller code is executing after deviceready as per requirement from Cordova
I have tried
- Setting HighAccuracy to false
- Removing geolocation plugin so that it uses default location from Wifi
- Device reboot
- Clearing browser cache
- Airplane mode on/off
- Wifi on/off
- Mobile data on/off
But I am unable to get lat, long and geolocation always gets timeout.
It only works when I enabled Location/GPS from setting. After enabling it code is working as expected.
enableHighAccuracy:false
Nexus 4, OS 5.0 => GPS required to get position Moto G, OS 4.4 => GPS required to get position Now miracle Samsung I9300 Galaxy S III, OS 4.3 => GPS NOT required to get position, from same code. This question is still unanswered, lets see if this can help someone in finding solution. – Selfsuggestion