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

后端 未结 8 1267
萌比男神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:02

    In case some of you are still experiencing this issue, I was able to get the navigator.geolocation.getCurrentPosition() to work for me by setting some values for the options parameter, as follows:

    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(  
          async (p) => {
            await this.workMyCurrentPosition(p);
          },
          (e) => this.navigatorError(e),
          { timeout: 7000, enableHighAccuracy: true, maximumAge: 0 }
        );
    }
    

    Hope it works for you!

提交回复
热议问题