navigator.geolocation.getCurrentPosition() never returns in WebView on Android

后端 未结 8 1274
萌比男神i
萌比男神i 2021-02-18 16:27

I am trying to access the HTML Geolocation API available in Android WebView (using SDK version 24).

The main problem is that the call to navigator.geolocat

8条回答
  •  余生分开走
    2021-02-18 17:25

    Looks like there are 2 different issues in your case:

    1. getCurrentPosition never fails
    2. getCurrentPosition never succeed

    First point could be just because method has infinite timeout

    The default value is Infinity, meaning that getCurrentPosition() won't return until the position is available.

    Second point could be tricky, there is a param maximumAge which means

    The PositionOptions.maximumAge property is a positive long value indicating the maximum age in milliseconds of a possible cached position that is acceptable to return. If set to 0, it means that the device cannot use a cached position and must attempt to retrieve the real current position. If set to Infinity the device must return a cached position regardless of its age.

    0 by default means that device won't use cached position and will try to fetch the real one and it could be an issue for long response.

    Also you could check this reporst which could mean that this API doesn't work really good on Android: https://github.com/ionic-team/ionic-native/issues/1958 https://issues.apache.org/jira/browse/CB-13241

    *Cordova leaves geolocation stuff for browser.

提交回复
热议问题