Ionic with Android Emulator: Automatically send location?
Asked Answered
M

1

11

I'm having an issue with my android emulator. When I close and re-open my app, the location is not sent automatically. I have to go into Extended Controls -> Location and click the 'Send' button for the Ionic Geolocation getCurrentPosition function to receive it.

When I boot up the android emulator and the app opens for the first time, this is not necessary. Any idea how to send the location automatically no matter what?

Midian answered 3/10, 2017 at 20:15 Comment(2)
did you tried in mobile ? is this behaviour seen in mobile also? generally emulator doesn't perform the way you want to define themQuoin
It works fine on a mobile device for some reason. It's just android emulator.Midian
Q
3

Generally for the Testing of Plugins we need to verify in the real device, but as your original question about using it in Emulators, for this to work out ,

  1. Try to clear the cordova Cache ( if you are using Visual Studio , you can do it like Tools->Options )

  2. Try to add watchPosition function with enableHighAccuracy : true

navigator.geolocation.watchPosition(onSuccess, onError, { 
    timeout:40000,
    enableHighAccuracy: true 
});

Update :

After a quick googling , found this link , It states that :

Starting with Chrome 50, Chrome no longer supports obtaining the user's location using the HTML5 Geolocation API from pages delivered by non-secure connections. This means that the page that's making the Geolocation API call must be served from a secure context such as HTTPS.

A possible solution can be like :

By adding appropriate permissions on Android platform, open your project, search for AndroidManifest.xml and add these lines:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />

For more Info Read this article and this thread

Quoin answered 7/10, 2017 at 11:4 Comment(2)
Thanks for the suggestions. Unfortunately, I've been battling with this issue for a while and it seems to be something that none of those solutions could remedy. The work-around will suffice for now.Midian
I have to go into Extended Controls -> Location and click the 'Send' button for the Ionic Geolocation getCurrentPosition function to receive it.Midian

© 2022 - 2024 — McMap. All rights reserved.