简体   繁体   中英

Android not giving Geolocation ionic 4

I am using Geolocation from @ionic-native/geolocation/ngx to show a user's location on entry to viewing a leaflet map, my code works for my browser and IOS phones (I run ionic serve --devapp).

I get an error from an Android phones which are '[object GeolocationPositionError]' with an error message of "Only secure origins are allowed (see: goo.gl/Y0ZkNV).". Could anyone help me please?

Also, the app asks automatically for permission to use GPS, there is no code in my app which asks for permission yet.

this.geolocation.getCurrentPosition().then((resp) => {
         resp.coords.latitude;
         resp.coords.longitude;
         let marker = L.marker([resp.coords.latitude, resp.coords.longitude]).addTo(this.map)
           .bindPopup('Your Location')
           .openPopup();
         this.map.setView([resp.coords.latitude, resp.coords.longitude], 15);
         console.log(resp.coords.latitude+" "+ resp.coords.longitude);
       }).catch((error) => {
         console.log('Error getting location ', error);
});

Are there any additional things I need to do to make the code work for Android?

Much appreciation :)

当使用cordova或capcitor for Ionic 4将应用程序部署到设备上时,华为设备将提供地理定位,但它不适用于ionic serve --devapp。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM