Geolocation HTML5 enableHighAccuracy True , False or Best Option?

You should also be aware that the implementation of this varies from phone OS to phone OS - what works on Android may or may not work on iOS, BlackBerry, WindowsPhone, etc.

You're almost there, you just need to:

  1. Specify enableHighAccuracy: true (you have it set to false)
  2. Handle the timeout error case in the error handler. If the error from the high accuracy query is timeout, then try it again with enableHighAccuracy: false.

Have a look at this sample code.

You should also note that when testing this on a few devices, it returns location derived from WiFi even when enableHighAccuracy: true.


The code mentioned here: http://jsfiddle.net/CvSW4/ did not work for me during error handling.

The reason is that the error functions accept a parameter named 'position' but use an object in the functions called 'error'.

function errorCallback_highAccuracy(position) { ... }
function errorCallback_lowAccuracy(position) { ... }

The solution to fix this was to switch the error methods to accept the input value as a parameter named 'error' and not 'position', since the error callbacks do not accept a position and throw an error object instead.

function errorCallback_highAccuracy(error) { ... }
function errorCallback_lowAccuracy(error) { ... }

I mention it here, because I could not post on the resulting example page and also, this is the location where I linked through to find the code sample mentioned above.