Cordova geolocation not working on android


#1

The error function is called and results [object position error]. It works as I want in the browser but not on my android device.

$scope.GetLocation = function() {
//navigator.geolocation.getCurrentPosition(Success, onError,posOptions);
$cordovaGeolocation
.getCurrentPosition(posOptions)
.then(Success, onError);
}
function onError(error){
alert(error)
}
function Success(position) {
var geocoder = new google.maps.Geocoder;
var infowindow = new google.maps.InfoWindow;
var pos = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
map.setCenter(pos);
geocoder.geocode({‘location’: pos}, function (results, status) {
if (status === ‘OK’) {
if (results[1]) {
map.setZoom(13);
var marker = new google.maps.Marker({
position: pos,
map: map
});
document.getElementById(‘origin-input’).value = results[1].formatted_address;
infowindow.setContent(results[1].formatted_address);
infowindow.open(map, marker);
} else {
window.alert(‘No results found’);
}
} else {
window.alert('Geocoder failed due to: ’ + status);
}
});
}


#2

I would suggest carefully looking at each step and outputting the results to the console.
For example, does the Success function get called?
What does the position value contain?
Does geoCoder get created correctly?
etc, etc.


#3

No the success function is not called, the error function is called and results [object position error]. It works as I want in the browser but not on my android device.


#4

What are your posOptions?
You able to inspect the error object for more information?


#5

and the plugin is installed?
$ cordova plugin add cordova-plugin-geolocation


#6

Thank you for replying Mr.Griffith. Here is my posOptions.
var posOptions = {timeout: 10000, enableHighAccuracy: true};
The cordova plugin is installed and is running fine in the browser but not on my android and for the error JSON.stringify is returning a null string for that object because it contains no properties.


#7

FYI: The plugin does not run in the browser, it uses the built in geolocation functions.
I would remove then reinstall the plugin.
Also are you calling this AFTER the deviceready event?


#8

No, it is being called on button click event.