Geolocation HTML5 enableHighAccuracy True , False or Best Option?

≡放荡痞女 提交于 2019-11-28 07:40:32
Kevin

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!