xelita / angular-cordova-geolocation

Bring Apache Cordova Geolocation API to AngularJS Apps...
14 stars 8 forks source link

angular-cordova-geolocation

Bring Apache Cordova Geolocation API to AngularJS Apps...

Define a simple service to deal with Cordova Geolocation Plugin (https://github.com/apache/cordova-plugin-geolocation).

Build Status

Usage

Include cordovaGeolocationModule.js in your Cordova application.

<script src="https://github.com/xelita/angular-cordova-geolocation/raw/master/js/cordovaGeolocationModule.js"></script>

or use the minified version:

<script src="https://github.com/xelita/angular-cordova-geolocation/raw/master/js/cordovaGeolocationModule.min.js"></script>

Add the module cordovaGeolocationModule as a dependency to your app module:

var myapp = angular.module('myapp', ['cordovaGeolocationModule']);

Use the cordovaGeolocationModule as controller dependency and call cordovaGeolocationModule API:

$scope.getCurrentPosition = function() {
    cordovaGeolocationService.getCurrentPosition(function(position){
        alert(
            'Latitude: '          + position.coords.latitude          + '\n' +
            'Longitude: '         + position.coords.longitude         + '\n' +
            'Altitude: '          + position.coords.altitude          + '\n' +
            'Accuracy: '          + position.coords.accuracy          + '\n' +
            'Altitude Accuracy: ' + position.coords.altitudeAccuracy  + '\n' +
            'Heading: '           + position.coords.heading           + '\n' +
            'Speed: '             + position.coords.speed             + '\n' +
            'Timestamp: '         + position.timestamp                + '\n'
        );
    });
};

Sample

A sample based on Ionic Framework can be found here: https://github.com/xelita/angular-cordova-plugins-sample