Ionic geolocation Only secure origins are allowed error


#1

I m building Android app in Ionic2 and Cordova i m using native Geolocation and google maps. Geo location in browser works well but when i run it on android I’m get flowing error: Only secure origins are allowed (see: https://goo.gl/Y0ZkNV).
Here is code:

Geolocation.getCurrentPosition(options).then((position) => {

      let latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

      let mapOptions = {
        center: latLng,
        zoom: 15,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      }

      this.map = new google.maps.Map(this.mapElement.nativeElement, mapOptions);
      this.initMapFinished(latLng);

    },function(err){console.log("ERROR: " + err.message)});

Serve locally using Https
#2

Hmm, nothing looks out of place.

Could you put together a simple demo of push it to github. I’d like to test it out.


#3

It’s a new secure procedure from google, Geolocation is only allowed from HTTPS and no longer supports HTTP. But i just couldn’t find a way to make it work. Can you help ?


#4

me too,
thought it was a Chrome Browser only problem, but i got this now on android emulator

ionic emulate android --dev -lc


#5

Indeed this is happening on my device now :frowning:
Working fine in the browser, seems to be a cordova issue with Geolocation.getCurrentPosition() etc


#6

An update on this is that for a signed production Android release the problem does not exist, so it’s only affecting the development build.
Also it’s only a problem when using live reload, if just doing “ionic run android” there is no error.
Google regard “localhost” as secure, but others as not.
I think it’s something to do with the fact that when the android build is connecting back to the dev machine, it has to do so on an IP address, so something other than localhost.
I think it’s this that is causing the problem.


#7

Have the same issue with Android emulator, however works fine in browser and iOS emulator.

How to test on Android emulator?


#8

so what to do if we need the livereload in order to develop the app?


#9

Is there a way to fix the Only secure origins are allowed error? I am testing my App on Android using ionic run android -l -c -s

it was working just fine a month ago! I tried it today and it just won’t work and it returns the above error.

  • I am using Ionic not Ionic2

Geolocation is not working on android
#10

Same problem here, in the browser it works, but as soon as u try the app in the android emulator u get that error. Any help?


#11

Hi,
I have come to the same conclusion.
The only workaround I see is to launch “Live Reload” under https but I don’t know if it’s possible ?


#12

Any news here? I get the same error now.


#13

Thank @danielabbatt it work for me.


#14

Hello,
I have same problem, did you find a solution with livereload ?

I let my message here : https://github.com/ionic-team/ng-cordova/issues/1413

Thank you


#15

Just run google chrome without web security. in linux

google-chrome.exe --disable-web-security

Will do. For windows search Internet.


#16

I have the same problem


#17

Where are you run the App on browser or some device?


#18

I run the App on Android device with --livereload


#19

@fdambrosio… You need run the app witthout --livereload, this is the problem, because when you use that flat, your app is not using the native components. I had the same issue.


#20

Thanks, yes I know, but I’m trying to find some way to do that…