javascript - GPS accuracy in HTML5 - Stack Overflow

admin2025-04-19  0

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?

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?

Share edited Feb 20, 2019 at 23:53 Neuron 5,9315 gold badges43 silver badges62 bronze badges asked Oct 7, 2012 at 10:56 DimansibDimansib 411 silver badge2 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

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./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

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

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745073383a283423.html

最新回复(0)