Hello, I’m a developer working on some fitness apps for the Samsung watches, and I’ve hit a roadblock with using the geolocation API. I’ve copied the source code from the Tizen docs on geolocation, and it’s still giving me errors. I’m testing on a Gear S3 Frontier and my location setting is on.
This is the code:
class GPS {
constructor() {
this.currentPosition = { latitude: 0, longitude: 0, distanceToStart: 0 };
this.startPosition = { found: false, latitude: 0, longitude: 0 };
this.tracker = 0;
this.startTracking();
}
found(lat, lon) {
if (!this.startPosition.found) {
this.startPosition.latitude = lat;
this.startPosition.longitude = lon;
}
this.currentPosition.latitude = lat;
this.currentPosition.longitude = lon;
this.currentPosition.distanceToStart = calcDistance(this.startPosition, this.currentPosition);
}
startTracking() {
if (navigator.geolocation) {
let settings = {enableHighAccuracy: true, timeout: 10000, maximumAge: 1000000};
navigator.geolocation.getCurrentPosition(location_success, location_fail, settings);
// this.tracker = navigator.geolocation.watchPosition(location_success, location_fail, settings);
} else {
output.innerHTML = ‘Geolocation is not supported.’;
}
}
stopTracking() {
if (navigator.geolocation) {
navigator.geolocation.clearWatch(this.tracker);
} else {
output.innerHTML = ‘Geolocation is not supported.’;
}
}
}
function location_success(position) {
gps.found(position.coords.latitude, position.coords.longitude);
output.innerHTML = "Position found: ", gps.currentPosition;
}
function location_fail(error) {
switch (error.code) {
case error.PERMISSION_DENIED:
output.innerHTML = ‘User denied the request for Geolocation.’;
break;
case error.POSITION_UNAVAILABLE:
output.innerHTML = ‘Location information is unavailable.’;
break;
case error.TIMEOUT:
output.innerHTML = ‘The request to get user location timed out.’;
break;
case error.UNKNOWN_ERROR:
output.innerHTML = ‘An unknown error occurred.’;
break;
}
gps.startTracking();
}
I keep getting the error “location information is unavailable.” If anyone has successfully figured out how to implement this into a web app, please let me know. Any help will be appreciated. Thanks!
Kollin