Dimansib
Dimansib

Reputation: 41

GPS accuracy in HTML5

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:

  1. I run a HTML5 app on iPhone, and accuracy begins falling. (from 150 to 1500 meters)
  2. Then I run a native app with maps on iPhone, like google maps, than I wait until it found my position.
  3. Then I go to my HTML5 app in browser.

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

Answers (2)

Greg Wilson
Greg Wilson

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

Miha Rekar
Miha Rekar

Reputation: 1546

Use enableHighAccuracy with navigator.geolocation.getCurrentPosition. Here is all you need to know: HTML5 Doctor

Upvotes: 1

Related Questions