How can I get reasonably accurate GPS positioning?
I'm trying to create a simple golf app for my "LG Leon LTE" phone that tells me how far I have hit each shot. My plan is to use the GPS only when needed - to get the position of my starting point and then get the position of my ending point, and calculate the distance between them. I don't think I need continuous updates.
I wrote a test program that uses the following to get a single position at a starting point and an ending point:
locationManager.requestSingleUpdate(LocationManager.GPS_PROVIDER, locationListener, null);
My locationlistener includes:
longitude = loc.getLongitude();
latitude = loc.getLatitude();
I also include:
accuracy = loc.getAccuracy();
numberOfSatellites = loc.getExtras().getInt("satellites");
And to calculate the distance between the two points I use:
loc.distanceBetween(oldLatitude, oldLongitude, newLatitude, newLongitude, result);
distance = ((int) ((result[0] * 1.09361) + 0.5)); // meters to yards
The manifest for my app includes:
android.permission.ACCESS_FINE_LOCATION
android.hardware.location.gps
and My phone's "Location" function is on, and the "Location Mode" setting is "GPS only"
Hoping to improve the accuracy, I collect 5 data points at the starting and ending location, and I calculate the distance traveled two ways:
- using the "average" of the starting and ending positions, and
- using the "best" starting and ending positions (those with the lowest "accuracy" value).
My simple tests are conducted in front of my house in a residential area with houses on only one side of the street, and they consist of:
- standing in one place and displaying the distance traveled, and
- pacing 20 yards and displaying the distance traveled. (Note that, on the golf course I consistently pace 100 yards and am accurate within +-2 yards.
The results are very confusing.
- Standing still produces "distance traveled" results ranging from 0 to 20 yards, usually in the range of 7-10 yards.
- Pacing 20 yards produces results ranging from 1-15 yards. (I've never gotten 20 yards or more.)
- Neither "average" nor "best" calculations consistently show an advantage. Sometimes "average" produces a more accurate result, and sometimes "best" is best.
- The number of satellites is never more than 9. Sometimes it's 1, and sometimes it's 0!! (What does it mean to get a position with 0 satellites?) I downloaded the "GPS essential" app, and it shows 20 or more satellites when I stand in front of my house!
Can someone suggest ways to improve my results - more satellites, more accuracy? (Golf range finder apps for my phone seem to be more accurate; how do they do it?)
Thank you.