Skip to content

Instantly share code, notes, and snippets.

@brunoksato
Created June 5, 2015 04:21
Show Gist options
  • Save brunoksato/5e7f9b2916289d1649a4 to your computer and use it in GitHub Desktop.
Save brunoksato/5e7f9b2916289d1649a4 to your computer and use it in GitHub Desktop.
Gps Enable Cordova Ionic
function GeolocationSync(){
var existLatLong = Application.getPosition();
if(existLatLong === null){
$ionicLoading.show({
templateUrl: 'templates/components/sync.html',
scope: $scope
});
if(window.cordova !== undefined){
if($cordovaDevice.getDevice().platform === "Android"){
isGpsEnabled();
var intervalPromisse = $interval(function(){
isGpsEnabled();
},4000);
}
else{
getLocation();
}
}
else{
getLocation();
}
}
function isGpsEnabled() {
var gpsEnabled = window.plugins.locationAndSettings;
gpsEnabled.isGpsEnabled(function(result) {
if (result === false) {
if($scope.openConfigLocation === false)
switchToLocationSettings();
}
else{
$interval.cancel(intervalPromisse);
getLocation();
}
}, function() {
alert("error");
});
}
function switchToLocationSettings() {
var configLocation = window.plugins.locationAndSettings;
configLocation.switchToLocationSettings(function(result) {
if(result){
$scope.openConfigLocation = true;
}
}, function() {
alert("error");
});
}
function getLocation(){
var watchOptions = {
frequency : 100000,
enableHighAccuracy: true
};
var watch = $cordovaGeolocation.watchPosition(watchOptions);
watch.then(
null,
function(err) {
console.log(err);
},
function(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
Application.setPosition([lat, lng]);
$ionicLoading.hide();
});
}
}
@shankscript
Copy link

window.plugins === undefined ;(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment