Ionic Geolocation with Background Location

Ionic Geolocation with Background Location

Ionic Geolocation with Background Location Service

Free!

Not yet rated
Neven

Neven

Member since 2015

Details

Version:
1.0
Size:
3mb
Ionic:
1.x
Platforms:
iOS
Released:
8 years ago
Updated:
4 years ago
Category:
Starters
Tags:
Ionic, Geolocation, Cordova, Background Location, Speed, GPS, Latitude, Longitude

**THIS APP MIGHT NOT WORK ON ANDROID DUE TO NEW SDK CHANGES.

I am trying to find a fix for android. If you purchased this and need a refund send me an email. apologies.




Similar to Ionic Geolocation but with Background Location Updates enabled.

A barebone ionic geolocation application for iOS and Android that reads your phone gps location and displays it. It's all you need to get started on your location based application. I know you can figure it out on your own, but this will save you time, especially when you get stuck :)

I am updating the location and speed every second, you can change this to what you need. I haven't had any luck with using cordova watchPosition so I am doing my own polling here. Speed is displayed in Meters per second. You can now check if Location Service is disabled for your app.

After you install ionic you have to install cordova geolocation plugin.

Check out my other useful starters are here: Great Ionic Starters.

Documentation

  • All of the geolocation logic is contained in 'Geolocation' service in services.js
  • Two things you can modify in services are the handling of errors and geolocation options

     var options = {
              enableHighAccuracy: true, // USE HIGH ACCURACY
              timeout: 15000, // HOW LONG TO WAIT FOR A RESPONSE
              maximumAge: 0 // SET TO ZERO SO NEW VALUES ARE ALWAYS RETURNED
          };
    
         function showError(error) {
                console.log('Unable to get the location.'); // LOG ERRORS
         }
  • DashCtrl controller in controllers.js is used to display the values from geolocation service
  • Data is displayed in tab-dash.html
  • Changes to the values are wrapped in $scope.$apply(function () { } to enable data binding
  • Geolocation data is obtained by calling Geolocation.checkLocation(callback), this function takes a function as parameter to return the value
  • You can change the 1000 (1 second) interval polling on this line:
  • setInterval( function(){ Geolocation.checkLocation( $scope.callback ); }, 1000);
  • Call Geolocation.isGPSEnabled() to see if Location Service is enabled
  • Geolocation.getPosition() returns a result array
  • return new Array(latitude, longitude, altitude, speed, GPSEnabled); where you can check the last element to see if GPS is enabled.

Installation

Install Ionic

Open zipped folder in terminal

  • go to the project folder
  • Install Ionic sudo npm install -g ionic
  • ionic platform add ios
  • ionic platform add android
  • cordova plugin add cordova-plugin-geolocation
  • cordova plugin add cordova-plugin-mauron85-background-geolocation
  • ionic emulate ios
  • ionic run android (use run if you use genymotion)
  • the app will ask you to share your location
  • If you are using an emulator you will have to trigger the location manually

Common Issues

  • There are some reported issues with nexus phones and speed variable. Try setting enableHighAccuracy to false in the options array. If this doesn't work then there is an incompatibility with cordova geolocation and the new android sdk. I am still trying to resolve this.
  • Notification text is set to 'disabled' on android. In the code remove this line from the configuration.

Payment Information

  • The payment on this site is processed by Stripe.com and sometimes your bank will decline the charges if they don't recognize it. You can contact your bank or try a different card.

Support

  • Leave a comment if you get stuck on anything
  • If you email me directly it might get caught in the spam filter
  • And Kudos if you leave a Rating! =)

Stay in Touch



Icon made by Freepik from www.flaticon.com is licensed under CC BY 3.0

Hey there! You'll need to log in before you can leave a comment here.

Asier

Asier   ·   8 years ago

Hi, I just purchased this plugin but no data appears on front page, just Latitude: {{location[0]}}, etc and these errors on console: ReferenceError: backgroundGeoLocation is not defined at http://localhost:8100/js/controllers.js:41:3 at http://localhost:8100/lib/ionic/js/ionic.bundle.js:53329:19 at Object.ionic.Platform.ready (http://localhost:8100/lib/ionic/js/ionic.bundle.js:2135:9) at Object.self.ready (http://localhost:8100/lib/ionic/js/ionic.bundle.js:53327:26) at new <anonymous> (http://localhost:8100/js/controllers.js:18:18) at invoke (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17762:17) at Object.instantiate (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17770:27) at http://localhost:8100/lib/ionic/js/ionic.bundle.js:22326:28 at self.appendViewElement (http://localhost:8100/lib/ionic/js/ionic.bundle.js:56883:24) at Object.switcher.render (http://localhost:8100/lib/ionic/js/ionic.bundle.js:54995:41) <ion-nav-view name="tab-dash" class="view-container tab-content" nav-view="active" nav-view-transition="ios">

Neven

Neven   ·   8 years ago

@Asier are you starting the project with 'ionic emulate ios' ?

Neven

Neven   ·   8 years ago

@Asier you have to use an iOS or Android emulator or device. You cannot start the project via `ionic serve`

Asier

Asier   ·   8 years ago

Thanks Neven, it works on emulator

Toke Refstrup

Toke Refstrup   ·   8 years ago

Will this be able to get GPS coords even when the screen is locked?

Neven

Neven   ·   8 years ago

@Toke yes I have just tested it for iOS on the lock screen and I am getting location updates. I tested using XCODE and iPhone simulator using simulated city drive.

Miguel Clement

Miguel Clement   ·   8 years ago

just bought the app and deployed to android nexus 6, lat and long are visible but the speed field is blank. I also noticed that there is a Background tracking notification, but it says "DISABLED". any idea how I can get this going? I did get this error during deploy "BackgroundGeolocationPlugin.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details."

Neven

Neven   ·   8 years ago

@Miguel I will have to check nexus 6 specifically. Are you testing on real hardware? And what Android Version does it have?

Miguel Clement

Miguel Clement   ·   8 years ago

@Neven yes it is real hardware. I will try on an Iphone later today. The nexus is running android 6.0.1

Neven

Neven   ·   8 years ago

@Miguel for speed to show up on hardware you will actually have to go for a run or drive in a car. And for the notification text it should have not showed up. It is configured in controllers.js. Look for backgroundGeoLocation.configure. You can see all of the configure options here https://github.com/mauron85/cordova-plugin-background-geolocation. For some reason my genymotion emulator isn't working for this.

Tord Nilsen

Tord Nilsen   ·   8 years ago

Same problem for me as well, Background tracking notification, but it says "DISABLED", speed 0 m/s Nexus 5p

Neven

Neven   ·   8 years ago

@Tord sorry to hear that, as of now I can't test it on that specific device. The best I can do is issue you a refund. Let me know.

Neven

Neven   ·   8 years ago

I think there is an incompatibility with the new android sdk and cordova geolocation on some devices. You could try a couple things. In the services.js try to change enableHighAccuracy to false. And in platforms/android/AndroidManifest.xml add all the location permissions : <uses-permission android:name="android.permission.ACCESS_LOCATION" /> <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" /> <uses-permission android:name="android.permission.ACCESS_GPS" /> <uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />

Brendan

Brendan   ·   8 years ago

Hey @Neven, Thanks for this starter, was a great help in quickly prototyping an app. I have just been having one issue where when the app is left and chrome browser is focused I get the following errors in ADB Log Cat. I am currently calling 'ionic run android' to test on LG G3. LocationManagerService(1084): Location listener died LocationManagerService(1084): RemoteException calling onLocationChanged on Reciever[44852b78 listener UpdateRecord[fused com.ionicframework.starter(10176) Request[ACCURACY_BLOCK fused requested=0 fastest=0]]] I am not really sure why this is, Is this something anyone has experienced before?

Neven

Neven   ·   8 years ago

@Brendan is the app crashing in the background? And are you adding some kind of http request to save location?

salih onder

salih onder   ·   8 years ago

1-When I turned off GPS, app doesnt ask or force to open. 2-When I switch to other app, on background it doestn track I didnt get how this app works on background. It seems it doesnt work. HELP!!!!!!!!

Neven

Neven   ·   8 years ago

Hey can you tell me what cordova version and what android version you are using?

  ·   just now

{{ reply.comment }}



Hey there! You'll need to log in before you can leave a comment here.

Joao Victor Luz

Joao Victor Luz   ·   8 years ago

@Neven Still not working for Android?

Neven

Neven   ·   8 years ago

Hey I don't have a good way of testing this yet on android. But I assume it isn't working since it was reported by many users as not working.

  ·   just now

{{ reply.comment }}



Hey there! You'll need to log in before you can leave a comment here.

Sven

Sven   ·   8 years ago

Hello. The geolocation does not work with iOS 10. Any hints? YES - I've checked location setup at the phone. With iOS 9.xxx it still works. Thank you in advance. Cheers.

Neven

Neven   ·   8 years ago

Hey, iOS just came out :) so I didn't get to testing it yet. I will look into it.

Neven

Neven   ·   8 years ago

iOS 10 I mean

Sven

Sven   ·   8 years ago

Hi Neven. I found a solution: Geolocation is only supported if html is called via https-Request. Cheers Sven

  ·   just now

{{ reply.comment }}



Hey there! You'll need to log in before you can leave a comment here.

Arjun G N

Arjun G N   ·   7 years ago

I would like to buy this if it gets working on latest android.

  ·   just now

{{ reply.comment }}



Hey there! You'll need to log in before you can leave a comment here.

Muhammad Usman

Muhammad Usman   ·   6 years ago

Still not working for Android?

Neven

Neven   ·   6 years ago

Sorry haven't worked on it. I need to migrate all of these projects to the new Ionic

  ·   just now

{{ reply.comment }}



Hey there! You'll need to log in before you can leave a comment here.

Jeremy Kabaya

Jeremy Kabaya   ·   4 years ago

Does it work for android ver 7 and above?

  ·   just now

{{ reply.comment }}



Hey there! You'll need to log in before you can leave a comment here.

venu

venu   ·   4 years ago

Hi, Is plugin push data to server even after app closing or terminate every 20 minutes ?

  ·   just now

{{ reply.comment }}



Hey there! You'll need to log in before you can leave a comment here.

  ·   just now

{{ comment.comment }}

  ·   just now

{{ reply.comment }}



Hey there! You'll need to log in before you can leave a comment here.

  ·   just now

{{ comment.comment }}

  ·   just now

{{ reply.comment }}



Hey there! You'll need to log in before you can leave a comment here.

venu

venu   ·   4 years ago

Hi, Is plugin push data to server even after app closing or terminate every 20 minutes ?

  ·   just now

{{ reply.comment }}



Hey there! You'll need to log in before you can leave a comment here.

Jeremy Kabaya

Jeremy Kabaya   ·   4 years ago

Does it work for android ver 7 and above?

  ·   just now

{{ reply.comment }}



Hey there! You'll need to log in before you can leave a comment here.

Muhammad Usman

Muhammad Usman   ·   6 years ago

Still not working for Android?

Neven

Neven   ·   6 years ago

Sorry haven't worked on it. I need to migrate all of these projects to the new Ionic

  ·   just now

{{ reply.comment }}



Hey there! You'll need to log in before you can leave a comment here.

Arjun G N

Arjun G N   ·   7 years ago

I would like to buy this if it gets working on latest android.

  ·   just now

{{ reply.comment }}



Hey there! You'll need to log in before you can leave a comment here.

Sven

Sven   ·   8 years ago

Hello. The geolocation does not work with iOS 10. Any hints? YES - I've checked location setup at the phone. With iOS 9.xxx it still works. Thank you in advance. Cheers.

Neven

Neven   ·   8 years ago

Hey, iOS just came out :) so I didn't get to testing it yet. I will look into it.

Neven

Neven   ·   8 years ago

iOS 10 I mean

Sven

Sven   ·   8 years ago

Hi Neven. I found a solution: Geolocation is only supported if html is called via https-Request. Cheers Sven

  ·   just now

{{ reply.comment }}



Hey there! You'll need to log in before you can leave a comment here.

Joao Victor Luz

Joao Victor Luz   ·   8 years ago

@Neven Still not working for Android?

Neven

Neven   ·   8 years ago

Hey I don't have a good way of testing this yet on android. But I assume it isn't working since it was reported by many users as not working.

  ·   just now

{{ reply.comment }}



Hey there! You'll need to log in before you can leave a comment here.

salih onder

salih onder   ·   8 years ago

1-When I turned off GPS, app doesnt ask or force to open. 2-When I switch to other app, on background it doestn track I didnt get how this app works on background. It seems it doesnt work. HELP!!!!!!!!

Neven

Neven   ·   8 years ago

Hey can you tell me what cordova version and what android version you are using?

  ·   just now

{{ reply.comment }}



Hey there! You'll need to log in before you can leave a comment here.

Neven

Neven   ·   8 years ago

@Brendan is the app crashing in the background? And are you adding some kind of http request to save location?

Brendan

Brendan   ·   8 years ago

Hey @Neven, Thanks for this starter, was a great help in quickly prototyping an app. I have just been having one issue where when the app is left and chrome browser is focused I get the following errors in ADB Log Cat. I am currently calling 'ionic run android' to test on LG G3. LocationManagerService(1084): Location listener died LocationManagerService(1084): RemoteException calling onLocationChanged on Reciever[44852b78 listener UpdateRecord[fused com.ionicframework.starter(10176) Request[ACCURACY_BLOCK fused requested=0 fastest=0]]] I am not really sure why this is, Is this something anyone has experienced before?

Neven

Neven   ·   8 years ago

I think there is an incompatibility with the new android sdk and cordova geolocation on some devices. You could try a couple things. In the services.js try to change enableHighAccuracy to false. And in platforms/android/AndroidManifest.xml add all the location permissions : <uses-permission android:name="android.permission.ACCESS_LOCATION" /> <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" /> <uses-permission android:name="android.permission.ACCESS_GPS" /> <uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />

Neven

Neven   ·   8 years ago

@Asier are you starting the project with 'ionic emulate ios' ?

Tord Nilsen

Tord Nilsen   ·   8 years ago

Same problem for me as well, Background tracking notification, but it says "DISABLED", speed 0 m/s Nexus 5p

Neven

Neven   ·   8 years ago

@Miguel for speed to show up on hardware you will actually have to go for a run or drive in a car. And for the notification text it should have not showed up. It is configured in controllers.js. Look for backgroundGeoLocation.configure. You can see all of the configure options here https://github.com/mauron85/cordova-plugin-background-geolocation. For some reason my genymotion emulator isn't working for this.

Miguel Clement

Miguel Clement   ·   8 years ago

@Neven yes it is real hardware. I will try on an Iphone later today. The nexus is running android 6.0.1

Neven

Neven   ·   8 years ago

@Miguel I will have to check nexus 6 specifically. Are you testing on real hardware? And what Android Version does it have?

Miguel Clement

Miguel Clement   ·   8 years ago

just bought the app and deployed to android nexus 6, lat and long are visible but the speed field is blank. I also noticed that there is a Background tracking notification, but it says "DISABLED". any idea how I can get this going? I did get this error during deploy "BackgroundGeolocationPlugin.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details."

Neven

Neven   ·   8 years ago

@Toke yes I have just tested it for iOS on the lock screen and I am getting location updates. I tested using XCODE and iPhone simulator using simulated city drive.

Toke Refstrup

Toke Refstrup   ·   8 years ago

Will this be able to get GPS coords even when the screen is locked?

Asier

Asier   ·   8 years ago

Thanks Neven, it works on emulator

Neven

Neven   ·   8 years ago

@Asier you have to use an iOS or Android emulator or device. You cannot start the project via `ionic serve`

Asier

Asier   ·   8 years ago

Hi, I just purchased this plugin but no data appears on front page, just Latitude: {{location[0]}}, etc and these errors on console: ReferenceError: backgroundGeoLocation is not defined at http://localhost:8100/js/controllers.js:41:3 at http://localhost:8100/lib/ionic/js/ionic.bundle.js:53329:19 at Object.ionic.Platform.ready (http://localhost:8100/lib/ionic/js/ionic.bundle.js:2135:9) at Object.self.ready (http://localhost:8100/lib/ionic/js/ionic.bundle.js:53327:26) at new <anonymous> (http://localhost:8100/js/controllers.js:18:18) at invoke (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17762:17) at Object.instantiate (http://localhost:8100/lib/ionic/js/ionic.bundle.js:17770:27) at http://localhost:8100/lib/ionic/js/ionic.bundle.js:22326:28 at self.appendViewElement (http://localhost:8100/lib/ionic/js/ionic.bundle.js:56883:24) at Object.switcher.render (http://localhost:8100/lib/ionic/js/ionic.bundle.js:54995:41) <ion-nav-view name="tab-dash" class="view-container tab-content" nav-view="active" nav-view-transition="ios">

Neven

Neven   ·   8 years ago

@Tord sorry to hear that, as of now I can't test it on that specific device. The best I can do is issue you a refund. Let me know.

Hey there! You'll need to log in before you can leave a rating here.

There are no ratings for this starter yet

  ·     ·   just now

{{ rating.comment }}

  ·     ·   just now

{{ rating.comment }}