I am new to IBM Worklight.While using google map I need to get the current position of the device using gps.
I am not getting any error on emulator but in the phone getting the following alert
{"message":."Failed to start Geolocation service "," code":2}
The following code is using .
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);
}
});
}
Make sure you have the following permissions set in android\native\AndroidManifest.xml:
Also try adding the
enableHighAccuracy: true
option: