06-02-2018 23:16
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-02-2018 23:16
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Is the Geolocation watchPosition callback not working?
I've setup a simple test to record the coordinates on each successful call. I'm getting continuous coordinate changes while not moving. According to the coordinates, I traveled 343 feet - while standing still. I've included the code and the first section of the console log. Anyone else having problems? I thought it might be my watch or where I was standing, but the standard exercise application doesn't seem to have problem.
Thanks for any help,
Rich
import { geolocation } from "geolocation";
var Options = {enableHighAccuracy:true,maximumAge:5000};
var watchID = geolocation.watchPosition(OnSuccess, OnError, Options);
function OnSuccess(position) {
console.log(position.coords.latitude+","+position.coords.longitude);
}
function OnError(error) {
console.log("Error, Message:"+error.code+","+error.message);
}
Console log:
[10:15:50 PM]35.26927666666667,-120.66404166666666
[10:15:51 PM]35.26927666666667,-120.66405166666667
[10:15:52 PM]35.26927166666667,-120.664065
[10:15:53 PM]35.269268333333336,-120.66407833333334
[10:15:54 PM]35.26926666666667,-120.664085
[10:15:55 PM]35.269263333333335,-120.66408333333334
[10:15:56 PM]35.269261666666665,-120.66408333333334
[10:15:57 PM]35.26926,-120.66407666666667
[10:15:58 PM]35.26925833333333,-120.66407833333334
[10:15:59 PM]35.26925166666667,-120.66408
[10:16:00 PM]35.26925,-120.66408666666666
[10:16:01 PM]35.26924833333333,-120.66409
[10:16:02 PM]35.26924,-120.66408833333334
[10:16:03 PM]35.269235,-120.66408833333334
[10:16:04 PM]35.26922666666667,-120.66409
[10:16:05 PM]35.26922166666667,-120.66409666666667
[10:16:06 PM]35.26922,-120.66409666666667
[10:16:07 PM]35.269218333333335,-120.66409333333333
[10:16:08 PM]35.269216666666665,-120.66409166666666
[10:16:09 PM]35.269215,-120.66409833333333
[10:16:10 PM]35.26921166666666,-120.66409166666666
[10:16:11 PM]35.26921166666666,-120.66409333333333
[10:16:12 PM]35.26921,-120.66409833333333
[10:16:13 PM]35.26921,-120.66409333333333
[10:16:14 PM]35.26920833333333,-120.66409
[10:16:15 PM]35.26920333333333,-120.66408833333334
[10:16:16 PM]35.269205,-120.664085
[10:16:17 PM]35.2692,-120.66408166666666
[10:16:18 PM]35.2692,-120.66408166666666
[10:16:19 PM]35.26920166666667,-120.66408333333334
[10:16:20 PM]35.269196666666666,-120.66408333333334
[10:16:21 PM]35.269191666666664,-120.66408166666666
[10:16:22 PM]35.269185,-120.66408333333334
[10:16:23 PM]35.26918333333333,-120.664085
[10:16:25 PM]35.269175,-120.66408166666666
[10:16:25 PM]35.26917,-120.66408166666666
[10:16:26 PM]35.26916666666666,-120.664085
[10:16:27 PM]35.26917666666667,-120.66407666666667
[10:16:28 PM]35.26918333333333,-120.66407833333334
[10:16:29 PM]35.26918,-120.664085
[10:16:30 PM]35.26918333333333,-120.66408833333334
[10:16:31 PM]35.269178333333336,-120.66408833333334
[10:16:32 PM]35.26918166666667,-120.66408333333334
[10:16:33 PM]35.26918166666667,-120.664085
[10:16:34 PM]35.269178333333336,-120.66409166666666
[10:16:35 PM]35.26917666666667,-120.66409333333333
[10:16:36 PM]35.26917666666667,-120.66410166666667
[10:16:37 PM]35.269171666666665,-120.664105
[10:16:38 PM]35.26917666666667,-120.66410833333333
[10:16:39 PM]35.269185,-120.66411666666667
[10:16:40 PM]35.269191666666664,-120.664125
[10:16:41 PM]35.269193333333334,-120.66412666666666
[10:16:42 PM]35.269195,-120.66413833333333
[10:16:43 PM]35.269196666666666,-120.664145
[10:16:44 PM]35.2692,-120.66415666666667
[10:16:45 PM]35.269205,-120.664165
[10:16:46 PM]35.26920666666667,-120.66417333333334
[10:16:47 PM]35.26921333333333,-120.66418666666667
[10:16:48 PM]35.269216666666665,-120.66418
[10:16:49 PM]35.269216666666665,-120.66416833333334
[10:16:50 PM]35.26921333333333,-120.66416166666667
[10:16:51 PM]35.269216666666665,-120.66415333333333
[10:16:52 PM]35.269218333333335,-120.66414833333333
[10:16:53 PM]35.269216666666665,-120.66413166666666
[10:16:54 PM]35.269215,-120.66412166666667
[10:16:55 PM]35.26921166666666,-120.66411166666667
[10:16:56 PM]35.269215,-120.66411333333333
[10:16:57 PM]35.269215,-120.664105
[10:16:58 PM]35.269215,-120.664115
[10:16:59 PM]35.269215,-120.66411166666667
[10:17:00 PM]35.269218333333335,-120.66410833333333
[10:17:01 PM]35.269218333333335,-120.664105
[10:17:02 PM]35.269218333333335,-120.6641
[10:17:03 PM]35.269216666666665,-120.66409333333333
[10:17:04 PM]35.26922,-120.664095
[10:17:05 PM]35.269218333333335,-120.664085
[10:17:06 PM]35.26922166666667,-120.66408166666666
[10:17:07 PM]35.26922,-120.66407666666667
[10:17:08 PM]35.269218333333335,-120.66407166666667
[10:17:09 PM]35.26922166666667,-120.66407666666667
[10:17:10 PM]35.269225,-120.66407666666667
[10:17:11 PM]35.269223333333336,-120.66407333333333
[10:17:12 PM]35.26922666666667,-120.66406333333333
[10:17:13 PM]35.26922166666667,-120.66405833333333
[10:17:14 PM]35.26921333333333,-120.66405
[10:17:15 PM]35.26920833333333,-120.66404833333333
[10:17:16 PM]35.26921,-120.66405
[10:17:17 PM]35.26920833333333,-120.66404833333333
[10:17:18 PM]35.26920833333333,-120.664055
[10:17:19 PM]35.269223333333336,-120.66407666666667
[10:17:20 PM]35.26923166666667,-120.66407666666667
[10:17:21 PM]35.269241666666666,-120.66407833333334
[10:17:22 PM]35.269256666666664,-120.66408333333334
[10:17:23 PM]35.269261666666665,-120.66408333333334
[10:17:24 PM]35.269268333333336,-120.66408333333334
[10:17:25 PM]35.26927,-120.66408333333334
[10:17:26 PM]35.269265,-120.664085
[10:17:27 PM]35.26926666666667,-120.66408833333334
[10:17:28 PM]35.269263333333335,-120.664085
[10:17:29 PM]35.269265,-120.66408833333334
[10:17:30 PM]35.269265,-120.664085
[10:17:31 PM]35.269265,-120.66407833333334
[10:17:32 PM]35.26926,-120.664075
[10:17:33 PM]35.269265,-120.66407666666667
[10:17:34 PM]35.269263333333335,-120.664075
[10:17:35 PM]35.26925833333333,-120.66407333333333
[10:17:36 PM]35.269256666666664,-120.664075
[10:17:37 PM]35.269255,-120.66407833333334
[10:17:38 PM]35.269255,-120.66407666666667
[10:17:39 PM]35.26925833333333,-120.66408666666666
[10:17:40 PM]35.269256666666664,-120.66409
[10:17:41 PM]35.269256666666664,-120.66409166666666
[10:17:42 PM]35.269256666666664,-120.664095
[10:17:43 PM]35.26926,-120.66409666666667
[10:17:44 PM]35.26925833333333,-120.66409333333333
[10:17:45 PM]35.269261666666665,-120.66409333333333
[10:17:46 PM]35.26925833333333,-120.66409
[10:17:47 PM]35.26924833333333,-120.664095
[10:17:48 PM]35.26925833333333,-120.66409833333333
[10:17:49 PM]35.26926,-120.66410333333333
[10:17:50 PM]35.26925,-120.66410333333333
[10:17:51 PM]35.269241666666666,-120.66410166666667
[10:17:52 PM]35.269241666666666,-120.66410833333333
[10:17:53 PM]35.269238333333334,-120.66410666666667
[10:17:54 PM]35.269235,-120.66410333333333
[10:17:55 PM]35.269225,-120.66411
[10:17:56 PM]35.269225,-120.66411333333333

06-03-2018 06:00
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-03-2018 06:00
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
After looking at the data more closely I realized that a lot of the coordinates are well within the margin of error for a GPS, which I believe is 3 feet? As a test I'm going to change the logic to record the point only if the distance from the last recorded point is greater than 15 feet. That should be large enough to remove the margin of error. More later.

06-03-2018 13:13
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-03-2018 13:13
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
After changing the application to ignore any coordinate less than 15ft away, I'm still getting these "bad" GPS updates. It seems to be better in the places where I know I should be getting a good GPS signal. It's much more problematic under a roof or inside. I'm not sure I understand why. I thought either a GPS signal was received and correct (within the margin of error) or wasn't received. I didn't think it could be wrong. Anyone have information of this or can verify that they see the same thing or not?
Thanks, Rich
updated code:
import { geolocation } from "geolocation";
const DistanceUnits=5280;
const GPSEarthRadiusInDistanceUnits=3956;
const capturepoints=false;
var Options = {enableHighAccuracy:true,maximumAge:5000};
var connected=false;
var watchID = geolocation.watchPosition(OnSuccess, OnError, Options);
var prevLat=0;
var prevLng=0;
function OnSuccess(position) {
if (!connected){
connected=true;
prevLat=position.coords.latitude;
prevLng=position.coords.longitude;
if (capturepoints){
console.log(position.coords.latitude+","+position.coords.longitude+";");
}
else {
console.log("0 ft "+position.coords.latitude+","+position.coords.longitude);
}
}
var distance=CalcDistance(prevLat,prevLng,position.coords.latitude,position.coords.longitude);
if (distance[0]>15 || Math.abs(distance[1])>15 || Math.abs(distance[2])>15){
if (capturepoints){
console.log(position.coords.latitude+","+position.coords.longitude+";");
}
else {
console.log(distance[0]+" ft "+position.coords.latitude+","+position.coords.longitude);
}
prevLat=position.coords.latitude;
prevLng=position.coords.longitude;
}
//console.log(distance+" ft "+position.coords.latitude+","+position.coords.longitude);
}
function OnError(error) {
console.log("Error, Message:"+error.code+","+error.message);
}
function CalcDistance(lat1,lon1,lat2,lon2,BC)
{
var p = 0.017453292519943295; // Math.PI / 180
var Dist = 0.5 - Math.cos((lat2 - lat1) * p)/2 +
Math.cos(lat1 * p) * Math.cos(lat2 * p) *
(1 - Math.cos((lon2 - lon1) * p))/2;
//Substitute same Lng to get latitude distance
var LatDst=0.5 - Math.cos((lat2 - lat1) * p)/2 +
Math.cos(lat1 * p) * Math.cos(lat2 * p) *
(1 - Math.cos((lon1 - lon1) * p))/2;
//Substitute same Lat to get longitude distance
var LngDst=0.5 - Math.cos((lat1 - lat1) * p)/2 +
Math.cos(lat1 * p) * Math.cos(lat1 * p) *
(1 - Math.cos((lon2 - lon1) * p))/2;
//console.log("BC.GPSEarthRadiusInDistanceUnits*BC.Units"+BC.GPSEarthRadiusInDistanceUnits+","+BC.DistanceUnits)
LatDst = (2 * Math.asin(Math.sqrt(LatDst)))*GPSEarthRadiusInDistanceUnits*DistanceUnits;
LngDst = (2 * Math.asin(Math.sqrt(LngDst)))*GPSEarthRadiusInDistanceUnits*DistanceUnits;
if (lat1 < lat2) //moving south
LatDst = LatDst*-1;
if (lon1 < lon2) //moving west
LngDst = LngDst*-1;
return [(2 * Math.asin(Math.sqrt(Dist)))*GPSEarthRadiusInDistanceUnits*DistanceUnits,LatDst,LngDst]
// 2 * R; R = 3956 miles radius of earth, 5280 feet in a mile
}

06-03-2018 13:32
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


06-03-2018 13:32
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
As I understand it, GPS requires signal from multiple satellites. The more satellites the receiver can see, the better it is able to calculate its position. This would explain the degradation indoors. GPS was not originally intended to function indoors; its signal does not penetrate anywhere near as well as mobile phone signals.
Gondwana Software

06-03-2018 14:09
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-03-2018 14:09
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I forgot that the mobile phones use cell towers to calculate position. I was wondering why the phones are always so accurate. But this still begs the question, should the GPS signal register as "good" i.e. accurate if it's not? And a second question, why does my application which seems so straight forward not work when the exercise application doesn't seem to have a problem. Is my algorithm just too simple? Or maybe the exercise application is using my phone's GPS too? I'm going to have to power down my phone and test.
Rich

06-03-2018 14:26
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

06-03-2018 14:26
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I should have investigated a little more before posting the topic. But maybe it will help someone else since I haven't seen this subject on the site. The answers are here: https://www.gps.gov/systems/gps/performance/accuracy/
To be brief, most GPS smart phones are accurate to within 16ft. My use of 15 ft as way outside the margin of error was just wrong. In fact the US government has committed to be accurate to 25.6 feet. In use, the accuracy is really more like 2.3 feet. But, I think the 16 ft is closer to what I've experienced with the watch.

