Geolocation is not working on android

I test the code on web browser and iOS, it works perfectly. but on android i get error message :
console.log: Error: Only secure origins are allowed (see: https://goo.gl/Y0ZkNV). Is there any solution to this problem?

This is something I believed was fixe in the cordova-plugin-geolocation a few release ago.
Chances are you have an older version that does not include the fixes.

ionic plugin rm cordova-plugin-geolocation

ionic plugin rm cordova-plugin-geolocation@latest --save
1 Like

I did this:
ionic plugin rm cordova-plugin-geolocation

ionic plugin add cordova-plugin-geolocation@latest --save

but i get same error. here is my code:
navigator.geolocation.getCurrentPosition(

  (position) => {
    const geofence = this.geofenceService.create({
      longitude: position.coords.longitude,
      latitude: position.coords.latitude,
    });
           // this.map.setCenter({ lat: position.coords.latitude, lng: position.coords.longitude });


    this.transitionToDetailsPage(geofence);
  },
  (error) => {
    console.log('Error: ' + error.message);

  },
  { timeout: 10000, enableHighAccuracy: true }
);

ionic info
system information:

Cordova CLI: 6.5.0
Ionic Framework Version: 2.0.1
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.0.0
ios-deploy version: 1.9.1
ios-sim version: 5.0.13
OS: OS X El Capitan
Node Version: v7.5.0
Xcode version: Xcode 8.2.1 Build version 8C1002

Just google your error and found that post, maybe it could help:

I read this, but what is a solution to this problem?

Somewhere http is use instead of httpsā€¦but I personnaly donā€™t know the solution, just wanted to give a clue

here similar topics

Thanks reedrichards, a lot of people are facing same issue but still no solution, all are searching for the solution.

What worked for me was editing the Android Manifest as stated here:

http://www.gajotres.net/using-cordova-geoloacation-api-with-google-maps-in-ionic-framework/

Thanks all, issue is resolve by updating plugins and not using livereload in run command.

4 Likes

OMG thanks a lot for this comment!! NOT using --livereload in Android made it happen to work, finally!!

1 Like

Thanks for the comment ā€œnot using --livereloadā€. Now working for Android.

Dear Hassan,
I am facing still this issue. please explain how did you fix it? Thanksā€¦

would you like to change the second line from remove to add?

I succesfully solve this issue :slight_smile:

how please tell me ,attached some codes

Follow this link this might be work:
https://stackoverflow.com/questions/35146417/cordova-plugin-geolocation-not-working-on-android-device/45964843#45964843

Hi all, weā€™ve put together this guide for testing Geolocation on Android in the emulator. Iā€™ve run into the same issues others have here, and these tips resolve them: https://blog.ionicframework.com/testing-geolocation-on-android/

I simple remove the security from Chrome with this command.

In MacOs:
open -a Google\ Chrome --args --disable-web-security --user-data-dir

In Linux:
google-chrome --disable-web-security --user-data-dir

This remove security and Cross-Origin too.

How you solve GEOLOCATION ISSUE ?

@hassanShahzad Still i am facing the same problem.I update the all plugin but still its not working in android device.can you please guid me step by step?

Thanks.