Geolocation is not working on android


#1

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?


#2

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

#3

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


#4

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


#5

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


#6

Somewhere http is use instead of https…but I personnaly don’t know the solution, just wanted to give a clue

here similar topics


#7

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


#8

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/


#9

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


#10

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


#11

Thanks for the comment “not using --livereload”. Now working for Android.


#12

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


#13

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


#14

I succesfully solve this issue :slight_smile:


#15

how please tell me ,attached some codes


#16

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


#17

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/


#18

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.


#19

How you solve GEOLOCATION ISSUE ?