Hi,
First of all I would like to know what is best concerning battery usage/life:
call again "getCurrentPosition" after getting an error or a location update or just use watchPosition. I am developing my own running application for Gear S and it seems to me that "watchPosition" is overkill, i do not need an update every second or less.
on the other hand, getCurrentPosition in combination with setTimeout does not work properly:
function get_coordinates()
{
if (navigator && navigator.geolocation && navigator.geolocation.getCurrentPosition) {
var options = {enableHighAccuracy:true, timeout:3000};
navigator.geolocation.getCurrentPosition(onGpsSuccess, onGpsError, options);
}
}
function onGpsSuccess(pos)
{
if (pos.coords.latitude === 0 && pos.coords.longitude === 0) {
console.log('Unable to acquire your location');
}
else {
if(last_lat !== 0 && last_lon !== 0) {
calculate_distance(last_lat, last_lon, pos.coords.latitude, pos.coords.longitude);
//calculate_distance2(last_lat, last_lon, pos.coords.latitude, pos.coords.longitude);
}
last_lat = pos.coords.latitude;
last_lon = pos.coords.longitude;
}
var t = setTimeout(function () { get_coordinates(); }, 2000); // wait 2 seconds for the next call
//get_coordinates(); // get a new position immediately
}
Calling get_coordinates inside onGpsSuccess gives me the next update immediately, like watchPosition, but if use setTimeout I get following update many seconds later if not an error.
Thanks,
Sergio