i have following code:
ons.ready( function() { navigator.geolocation.getcurrentposition( function( position ) { geo.lat = position.coords.latitude; geo.lon = position.coords.longitude; } ); } );
sometimes, not time following error:
location access not available. error in error callbackid: geolocation54410059
i need user's location load data main page of app. best place this?
ons.ready fire when dom loaded, using cordova plugin in order geolocation position. can't use before cordova ready.
just do:
document.addeventlistener('deviceready', function () { // cordova ready navigator.geolocation.getcurrentposition(function( position ) { geo.lat = position.coords.latitude; geo.lon = position.coords.longitude; }); }, false);
and fine think.
edit :
try adding options function :
navigator.geolocation.getcurrentposition(function( position ) { geo.lat = position.coords.latitude; geo.lon = position.coords.longitude; }, { maximumage: 3000, timeout: 5000, enablehighaccuracy: true });
you can put whatever value want 'enablehighaccuracy' , 'maximumage' must provide 'timeout' option because there quirks in android:
android quirks
if geolocation service turned off onerror callback invoked after timeout interval (if specified). if timeout parameter not specified no callback called.
Comments
Post a Comment