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

后端 未结 8 1240
萌比男神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.

    0 讨论(0)
  • 2021-02-18 17:25

    For applications targeting Android N and later SDKs (API level > Build.VERSION_CODES.M), the method onGeolocationPermissionsShowPrompt (String origin, GeolocationPermissions.Callback callback) is only called for requests originating from secure origins such as HTTPS. On non-secure origins, geolocation requests are automatically denied.

    You could narrow down your problem by yourself if you had tried putting a breakpoint or a log inside the method.

    You have two options:

    1. Target a lower level API, which is obviously much easier but not really appreciated.
    2. Set up SSL in your website.
    0 讨论(0)
提交回复
热议问题