Ionic cordova-Geolocation

  • Install cordova plugin by running this command
  • Try to handle every possible situations like Location services disbaled / Or user don’t allow permission to your application

cordova plugin add org.apache.cordova.geolocation

and Then

.controller('YourCtrl', function (loadingService) {
    loadingService.show        
    var posOptions = {
        timeout: 10000,
        enableHighAccuracy: false
    }
    navigator.geolocation.getCurrentPosition(onPositionSuccess, onPositionError, posOptions)
    function onPositionSuccess(position) {         
        var _position = {
            latitude: position.coords.latitude,
            longitude: position.coords.longitude
        }
    //sucess handler code
    loadingService.hide()
    }
  function onPositionError(error) {
    //error handler code
    loadingService.hide()
  }
})
And if you get stuck… Ask Here

email me rajeevsharma86@gmail.com

Avatar
Rajeev Sharma
Technical Lead

software entrepreneur and father of a fairy tale!!!.

Related