
Ionic Geolocation
Ionic Geolocation - Read Your Phone GPS Location, Altitude and Speed
$4.00
Details
- Version:
- 1.0
- Ionic:
- 1.x
- Platforms:
- iOS, Android
- Released:
- 5 years ago
- Updated:
- 3 years ago
- Category:
- Starters
- Tags:
- ,
If you need to check location while the app is suspended check: Ionic Geolocation with Background Location
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 incontrollers.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 arrayreturn new Array(latitude, longitude, altitude, speed, GPSEnabled);
where you can check the last element to see if GPS is enabled.
Installation
Install Ionic
- Read Ionic Installation Guide
- Download genymotion if you plan to emulate on android - Genymotion download
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
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
Background Location
- If you need to check location while the app is suspended check: Ionic Geolocation with Background Location
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
- Visit my blog rubberchickin.com.