Search code examples
javascriptgeolocationaugmented-reality

Very High Accuracy in Html5 Geolocation


I'm trying to make an augmented reality game, in which the user can shoot other people who are using the web app with only their phone. The problem is, I need some way to figure out where a user is. I have thought of several ways to do this, as shown below:

  • HTML5 Geolocation
  • Using the Gyroscope and Accelerometer
  • Somehow using XMLHttpRequest to "ping" the server and calculate position based on response time
  • A combination of the last 2

So far, it's looking like I'm going to use geolocation, but the problem is it's not very accurate. I need accuracy to about a foot that updates pretty quickly. I want to do this without native iOS or Android. If needed, it can be a local thing where you have to be within a certain distance of each other, for example to connect to an access point. Thanks in advance.


Solution

  • The HTML5 Geolocation API has an enableHighAccuracy option that can be turned on in addition to a watchPosition method that will update when the device changes location.

    I've used the enableHighAccuracy option at work and in my experience it's usually pretty accurate within a few feet. Using it along with watchPosition would likely help you avoid erroneous coordinates since it updates on a set interval.

    See here for more details: https://developer.mozilla.org/en-US/docs/Web/API/Geolocation

    I can't really speak on the other methods you suggested, but I hope this was helpful.