Reputation: 41
As part of my diploma project I faced with with a problem of getting GPS coordinates. I have developed a program with JavaScript and HTML5 that gets coordinates from browser.
But the accuracy of the position is very low. I use a method watchPosition()
with timeout:1000
So here is my observation:
And now the accuracy is higher than it was (about 5-10 meters). What has happend? And how do I make the accuray high as it is now without running third-party apps?
Upvotes: 4
Views: 6064
Reputation: 2410
As Miha suggested, I suspect you need the enableHighAccuracy param, however, getCurrentPosition()
sometimes gives up too soon. It will give you a location event, but sometimes, the accuracy is less than desired.
I wrote a simple wrapper for watchLocation
that has a similar interface to getCurrentPosition
but allows you to specify a timeout value and an acceptable accuracy.
It's on github at https://github.com/gwilson/getAccurateCurrentPosition -- here's what the call looks like:
navigator.geolocation.getAccurateCurrentPosition(onSuccess, onError, {desiredAccuracy:20, maxWait:15000});
Translating the above options into english -- This will attempt to find the device location with an accuracy of at least 20 meters and attempt to achieve this accuracy for 15 seconds
Upvotes: 3
Reputation: 1546
Use enableHighAccuracy
with navigator.geolocation.getCurrentPosition
. Here is all you need to know: HTML5 Doctor
Upvotes: 1