themoose
themoose

Reputation: 149

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 :)

Upvotes: 2

Views: 371

Answers (1)

themoose
themoose

Reputation: 149

Huawei device will give geolocation when the app is deployed onto the device using cordova or capcitor for Ionic 4, but it won't work on ionic serve --devapp.

Upvotes: 1

Related Questions