Cacious
Cacious

Reputation: 165

How do I get the most accurate GPS coordinates of my device using JavaScript?

I want to get the most accurate GPS coordinates of my device using JavaScript. I have tried searching around but I can't find a solution that is accurate enough. I have tried using the HTML5 Geolocation API but it gives me the wrong values. The values are about 10KM off.

I think it is returning the coordinates of my wifi provider server or something. What I want it to do is to return the coordinates of my device instead. I think this can only be accurately achieved using the device's GPS.

I haven't found a way to make the geolocation API to explicitly use GPS in its positioning. I have read that, it prioritizes the GPS method on mobile but I haven't tried it. Anyway, I want a way to always use the GPS method for positioning even on my laptop and tablet. The app I am working on depends on high location accuracy.

If there is no way to make the Geolocation API to explicitly use the GPS method to return my device's coordinates, Are there other accurate methods I can use? Please help!

NOTE: I have already tried providing the { enablesHighAccuracy: true } option.

Upvotes: 1

Views: 2121

Answers (1)

Brad
Brad

Reputation: 163622

I have tried using the HTML5 Geolocation API but it gives me the wrong values. The values are about 10KM off.

The Geolocation API will give you the highest accuracy available provided by the device. Without seeing your code, it isn't possible to tell you what the problem is. All I can suggest is ensure that you're using watchPosition(), to give the underlying GPS time to get a fix. (And of course, enableHighAccuracy as you say you are already doing.)

I haven't found a way to make the geolocation API to explicitly use GPS in its positioning.

It's not possible.

Anyway, I want a way to always use the GPS method for positioning even on my laptop and tablet.

I don't know of any desktop browsers that utilize a GPS for location.

If there is no way to make the Geolocation API to explicitly use the GPS method to return my device's coordinates, Are there other accurate methods I can use?

I suppose you could always write a browser extension to execute some native code and get you the raw data. The upcoming Serial Port API may also be of interest to you.

Upvotes: 1

Related Questions