transistorsoft / cordova-background-geolocation-lt

The most sophisticated background location-tracking & geofencing module with battery-conscious motion-detection intelligence for iOS and Android.
http://www.transistorsoft.com/shop/products/cordova-background-geolocation
Other
655 stars 277 forks source link

How Can I Know If GPS is Enabled and If not How Can I open settings from APP #350

Closed vedantterkar closed 6 years ago

vedantterkar commented 6 years ago

I want to know if GPS is enabled and app is able to access the GPS, If any of this is not true, Then I'll like to open settings. Is this possible?

Environment

Actual Behavior

It just asks that APP requires Permission to access Location.

Context

I want to check GPS/location settings before start (if location is not enabled, I want to open settings) Is it possible?

christocracy commented 6 years ago

Listen to providerchange event.

vedantterkar commented 6 years ago

@christocracy , Is there any way to open location settings page?

Any API equivalent to: BackgroundGeolocation.showLocationSettings();?

christocracy commented 6 years ago

No, but I believe there are 3rd-party plugins that can do this.

vedantterkar commented 6 years ago

providerChange event listener is not working in my case..

I've written it like:

backgroundGeolocation.on("location", this.setLocation.bind(this), this.handleError.bind(this) );  
           /**RESPONSE FROM christocracy TO DETECT GPS CHANGES */
           backgroundGeolocation.on('providerchange', function(provider) {
             debugger
              console.log('- Provider Change: ', provider);
              console.log('  enabled: ', provider.enabled);
              console.log('  gps: ', provider.gps);
              console.log('  network: ', provider.network);
              console.log('  status: ', provider.status);
            if(provider.status != 3) 
            {
              alert("LOcation settings changed");
            }
          }); 
backgroundGeolocation.configure(this.config, this.setLocation.bind(this), this.handleError.bind(this) );  

Still when I turn off GPS or If I turn it on again.. Nothing is getting printed in logs and no Alert is coming.

Also There is one more issue, .configure() method always calls failureCallbackFn insted of calling SuucessCallbackFn

Can you please help in this?

christocracy commented 6 years ago

You're not attempting to boot this in the browser, are you?

christocracy commented 6 years ago

What is the error returned from failureCallbackFn?

christocracy commented 6 years ago

#configure failing is the issue. If #configure fails, nothing will work.

vedantterkar commented 6 years ago

It says invalid action.

On May 23, 2017 8:33 PM, "Chris Scott" notifications@github.com wrote:

What is the error returned from failureCallbackFn?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/transistorsoft/cordova-background-geolocation-lt/issues/350#issuecomment-303427070, or mute the thread https://github.com/notifications/unsubscribe-auth/AYzDUsLtOeDY9muFePcIrgcCbJ25oys2ks5r8vUigaJpZM4NjTv4 .

christocracy commented 6 years ago

Show me your $ cordova plugins

vedantterkar commented 6 years ago

Though configure is falling, call to start is working fine and it is fetching correctly fetching locations.

christocracy commented 6 years ago

Show me your $ cordova plugins and I'll tell you exactly what's going on.

vedantterkar commented 6 years ago

@christocracy, Here is output of cordova plugins command:

$cordova plugins cordova-background-geolocation-lt 2.7.1 "BackgroundGeolocation" cordova-custom-config 3.1.2 "cordova-custom-config" cordova-plugin-app-version 0.1.9 "AppVersion" cordova-plugin-background-fetch 4.0.2 "CDVBackgroundFetch" cordova-plugin-camera 2.2.0 "Camera" cordova-plugin-compat 1.1.0 "Compat" cordova-plugin-console 1.0.6 "Console" cordova-plugin-device 1.1.5 "Device" cordova-plugin-dialogs 1.3.3 "Notification" cordova-plugin-mauron85-background-geolocation 2.2.5 "CDVBackgroundGeolocation" cordova-plugin-network-information 1.3.1 "Network Information" cordova-plugin-splashscreen 4.0.2 "Splashscreen" cordova-plugin-sqlite-2 1.0.4 "SQLitePlugin" cordova-plugin-statusbar 2.2.2 "StatusBar" cordova-plugin-whitelist 1.3.2 "Whitelist" cordova.plugins.diagnostic 3.3.3 "Diagnostic" ionic-plugin-deeplinks 1.0.14 "Ionic Deeplink Plugin" ionic-plugin-keyboard 2.2.1 "Keyboard"

vedantterkar commented 6 years ago

@christocracy Also Is there any way to get location after every "n" minutes on IOS? I know there is locationUpdateInterval But I think it is Android specific. Any Idea for IOS?

christocracy commented 6 years ago

You problem is this:

cordova-plugin-mauron85-background-geolocation 2.2.5 "CDVBackgroundGeolocation"

You need to remove that. You can't use both Mauron85's old fork in addition to this plugin.

This plugin has a different API and config params. You need to start from scratch implementing my plugin. Your Javascript code for Mauron85's version is incompatible with mine.

christocracy commented 6 years ago

Also Is there any way to get location after every "n" minutes on IOS? I know there is locationUpdateInterval But I think it is Android specific. Any Idea for IOS?

My plugin includes my iOS background-fetch plugin as a dependency:

cordova-plugin-background-fetch 4.0.2 "CDVBackgroundFetch"

This plugin will fire its fetch event typically every 15min, even while the device is stationary.

vedantterkar commented 6 years ago

Can I make it customizable, Say If I want location after every 2 mins (ios)? Can I do it?

Thanks for your help :).

christocracy commented 6 years ago

iOS background-fetch API's minimum interval is 15 min.

vedantterkar commented 6 years ago

Hi, I uninstalled another plugin and tested this one. It works fine.

Now Just one question; Every time I call configure it asks the user for location sharing permission; though my app has been given location sharing permission as "Always"?

I don't want to show location sharing permission dialog box if permission is already given.

Any idea How can we do it?

Really Appreciate your help.

christocracy commented 6 years ago

The plugin does not ask for location permission if already granted.

christocracy commented 6 years ago

The question for you is: "why is the location permission being revoked causing the plugin to have to re-ask for permission?"

vedantterkar commented 6 years ago

@christocracy ,

I was uninstalling and re-installing app for testing purpose and thats why it was asking for location permissions again and again.

Now That issue is resolved.

As I mentioned earlier

@christocracy Also Is there any way to get location after every "n" minutes on IOS? I know there is locationUpdateInterval But I think it is Android specific. Any Idea for IOS?

As Location update interval is 15mins on IOS; I tried to use .on("heartbeat")API with heartbeatInterval: 60 (60 secs).

It works fine in both IOS and Android in foreground and background mode; But There is one issue which I noticed recently; After some time Let us say 10mins; instead of firing heartbeat event after specified interval (60sec) It was firing it after much larger time of 5minutes.

Is it because of my config settings?

 this.config = {
      desiredAccuracy: 10,
      stationaryRadius: 0,
      distanceFilter: 0,
      debug: true,
      stopOnTerminate: false,
      startForeground: true,
      locationProvider: 1,
      locationUpdateInterval: 60 * 1000
      fastestInterval: (60 * 1000) / 2,
      activitiesInterval: (60 * 1000) / 2,
      stopOnStillActivity: false,
      pauseLocationUpdates: false,
      activityType: 'AutomotiveNavigation',
      notificationText: this.notificationText,
      notificationTitle: this.notificationTitle,
      useSignificantChangesOnly: false,
      locationAuthorizationRequest: 'Always',
      activityRecognitionInterval: 100,
      heartbeatInterval: 60,
      preventSuspend: true,
      trackingMode: 'location'

    };

Or is it something else? Thanks in advance.

and as mentioned in documentation; .on("location") will be fired as soon as new location is detected, That means on IOS it'll be fired too right? or will it be fired after 15mins only even if .on('location') is changed?

And what is the minimum distance needs to be travelled to trigger .on('location')

christocracy commented 6 years ago

You are getting way off topic from the original subject "How Can I Know If GPS is Enabled and If not How Can I open settings from APP".

This issue is closed. I will talk no further on this thread.

vedantterkar commented 6 years ago

@christocracy, Thanks. I'll create new thread for this.

@christocracy

Created a new Thread: https://github.com/transistorsoft/cordova-background-geolocation-lt/issues/354