Why does my Cordova app ask for Geolocation permission even when the app is not being used ?

137 views
Skip to first unread message

Shahruk Khan

unread,
Oct 27, 2015, 12:46:17 PM10/27/15
to phonegap
I only want the Geolocation to track the user when the app is open. However, whenever I ask for the position it asks the user "Allow "MyApp" to access your location even when you are not using the app?

To do a test, I deleted my entire WWW folder (no changes to my config file or plugins) and used this: http://code.tutsplus.com/tutorials/build-an-exercise-tracking-app-geolocation-tracking--mobile-11070

and this asked for the RIGHT permission. This is because it is using cordova-1.7.0 I think.

Here is my code, which is the SAME code in the Fitness tracker example app:


  // Start tracking the User
    watch_id = navigator.geolocation.watchPosition(

      // Success
        function(position){
            alert('Hello World!');
        },

        // Error
        function(error){
            console.log(error);
        },

        // Settings
        { frequency: 3000, enableHighAccuracy: true });

Very confused, any ideas/help please?

Shahruk Khan

unread,
Oct 27, 2015, 12:46:48 PM10/27/15
to phonegap
Plugin version is:

cordova-plugin-geolocation 1.0.1 "Geolocation"

Jesse Monroy

unread,
Oct 28, 2015, 12:06:58 AM10/28/15
to phonegap
is cordova.js or phonegap.js in your HTML file?
If you are using more than one HTML file, you need the HTML element in each file.

Shahruk Khan

unread,
Oct 28, 2015, 12:41:12 AM10/28/15
to phonegap
Yes, i have this line:

    <script src="cordova.js"></script>

Shahruk Khan

unread,
Oct 28, 2015, 12:41:13 AM10/28/15
to phon...@googlegroups.com
Yeah, I have this line:

    <script src="cordova.js"></script>



--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
---
You received this message because you are subscribed to a topic in the Google Groups "phonegap" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/phonegap/9eACen4yCAE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to phonegap+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jesse Monroy

unread,
Oct 28, 2015, 3:49:47 PM10/28/15
to phonegap
Are you waiting for the 'deviceready' event before you make your call to the geolocation library?
Or are you using any other libraries before the 'deviceready' event?

Jesse

Shahruk Khan

unread,
Oct 29, 2015, 12:57:08 PM10/29/15
to phonegap
Yes I'm waiting for the  device ready event.

Shahruk Khan

unread,
Oct 29, 2015, 1:13:56 PM10/29/15
to phonegap
Actually you gave me an idea. I removed the cordova-plugin-geolocation and it worked fine.

So apparently that plugin is only if you want background access. Good to know! 


On Wednesday, October 28, 2015 at 3:49:47 PM UTC-4, Jesse Monroy wrote:

Shahruk Khan

unread,
Oct 29, 2015, 1:14:26 PM10/29/15
to phonegap
Problem solved, thank you!


On Tuesday, October 27, 2015 at 12:46:17 PM UTC-4, Shahruk Khan wrote:

Shahruk Khan

unread,
Oct 29, 2015, 1:49:03 PM10/29/15
to phonegap
Nevermind, that gave me the double prompt bug.

Final solution - I checked my plist file and in there, I saw an entry for "NSLocationAlwaysUsageDescription" and "NSLocationWhenInUseUsageDescription"

According to this ticket https://issues.apache.org/jira/browse/CB-8826, this means that it would request for the background permission first. I deleted that key and everything is now fixed.

Jesse Monroy

unread,
Oct 29, 2015, 4:08:39 PM10/29/15
to phonegap
@Shahruk,
I want to make sure I understand this correctly. You are using the plugin, but two permission used with iOS seem to have cause your issue? Could clarify your fix and results?

TIA
Jesse

jcesarmobile

unread,
Oct 30, 2015, 3:50:38 AM10/30/15
to phonegap
@Jesse, read the issue he linked.

The geolocation plugin ask for background geolocation first and he isn't using it.
It's been fixed on the developer branch but the plugin changes has not been released yet to npm

Jesse Monroy

unread,
Oct 30, 2015, 5:56:29 PM10/30/15
to phonegap
I read it again. It' unclear why that is important. As many of these reported issues go
the author drones on about some technical point and never get to the why
the repercussion of the. In fact on re-reading, I see github bot make the item relevant.

@jcesarmobile
Thanks for the clarification.
Jesse
Reply all
Reply to author
Forward
0 new messages