Reputation: 741
Status: Accepted best available answer with thanks after a week or so. Awaiting / inviting more answers with citations
This matter was complex. I am really thankful to ALL commentators and specially asciimo,Gabe Sechan,AlexWien. Please vote and/or answer further after due study.
Senario:
The Location.getLatitude()
in android returns double which has low precision.
Api http://developer.android.com/reference/android/location/Location.html
Example:
Edit-2 begin
I just tried to send GPS cordinates by emulator and 111.422006 auto converted to 111.422004999999998 in Double dlongi = loc.getLongitude(); String longi = dlati.toString(); System.out.println(longi);
Edit-2 end
Edit-3 begin
I sent the coordinates by emulator (by GPS device in reality) as 111.422006, the android API received it as double value of 111.42004999999998
Edit-3 end
Too late for: BigDecimal class is too late for that as it already gives a d/Double.
Question: What if full accuracy is required.
What is a way to get it with good precision or in another form other than doubles?
Just thought to share and make others notice this too.
Requests:
Please do not answer until you are sure of a good answer with citation
. This would help the communtiy.
Edit:
Looks like Gps coordinats by normal GPS devices are them self not 100% FULLY accurate near to 3 meter for example but looks like doubles further decrease the accuracy. that was my question actually.
Upvotes: 0
Views: 1986
Reputation: 28767
Your post shows that 111.422006 becomes to 111.422004999999, this is a difference of 0.00001 which cannot happen due double to Double casting.
This clearly shows that the reduction in precision is somewhere from emulator input and or internal GPS processing most probably for emulation purpose ( the emulator could interpolate when needed)
For sure it is not caused by type double.
For real GPS, even when android would cut off or round at the 6 digit after decimal points, this does not affect the positional accuarcy. gsp positions have an physical limit of 3m. when android would cut of that digit, the position can change by some centimeter. but that can safely be ignored, it is the position that the device tells, and that is the best known truth. you cannot improve. raising the number of digits does not improve GPS acuracy, you would need to have a better GpS antenna to improve acuracy.
Update:
Here the granularity of coordinates in meters related to used number of latitude / longitude digits:
This case is the worst case: the distance on equator from (0.0,0.0) to (0.0, lon2)
lon2= 0.1, meters = 11131.94558870502
lon2= 0.01, meters = 1113.194558870502
lon2= 0.0010, meters = 111.3194558870502
lon2= 1.0E-4, meters = 11.131945588705022
lon2= 1.0E-5, meters = 1.1131945588705023
lon2= 1.0E-6, meters = 0.11131945588705022
So 0.000001 is 11cm
You can calculate that by yourself, too:
Earth circumfence (approx) = 40.000 km
Divided by 360 degrees = 111.111 km = 111111 meters per degree (exactly it is 111319m)
1 digit after comma: 0.1: divide by 10= 11131.9 m
2 digits after comma: 0.01: divide by 100= 1113.19m
and so on, look at the table above.
If you want the result more official: look at the link which asciimo has posted:
Coordinates in Decimal degrees
Upvotes: 2
Reputation: 6783
Double precision is not the problem here. Try this:
System.out.println(111.422006);
The output will be:
111.422006
The input seems to be processed somehow, whyever... So it's possible, that with real GPS data, the precision is better then your test suggests, hopefully...
Upvotes: 0
Reputation: 240
Keep in mind that 3 meter latitudinal accuracy (for a very good consumer GPS receiver) only requires 5 decimal places.
Upvotes: 2