Geolocation always times out on real device (works in emulator)
Phonegap - Eclipse
The geolocation works in the emulator of eclipse, but it always times out
on my real devices. I have increased the timeout option and also tried to
set enablehighaccuracy to false so it wouldn't need the gps, but it
doesn't help. Any idea how to get it working on a real phone?
var options = {
enableHighAccuracy: true,
timeout: 30000,
maximumAge: 30000
};
$(document).on("pageshow", "#NieuweTip", function() {
navigator.geolocation.getCurrentPosition(onGeoSuccess, onGeoError, options);
});
function onGeoSuccess(position) {
lat = position.coords.latitude;
lon = position.coords.longitude;
console.log('CB lat-lon: ' + lat + '-' + lon);
var currentposition = new google.maps.LatLng(lat,lon);
console.log('CB currentposition: ' + currentposition);
var mapoptions = {
zoom:12,
center: currentposition,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"), mapoptions);
var marker = new google.maps.Marker({
position: currentposition,
map: map
});
}
// onError Callback receives a PositionError object
//
function onGeoError(error) {
console.log('CB on GeoError');
alert('Zet geolocatie aan');
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
No comments:
Post a Comment