Hi,
I am not getting lat./lang. on my ios device when clicking on button called distance for filter the records based on the location.
I have used below code
Service.js
.factory(‘UserLocation’, function($ionicPopup){
var userLat;
var userLon;
return{
setlocation:function(){
alert(" In side set location ");
var geooption={enableHighAccuracy: false,maximumAge :1000};
var geoSuccess = function(position) {
userLat=position.coords.latitude;
userLon=position.coords.longitude;
$ionicPopup.alert({
title: 'Title',
template: 'Your current location is set. Latitude='+userLat+" Longitude = "+userLon
});
//calculation for distance
}; // var geoSuccess
var geoError = function(err){
isLocationSet=false;
$ionicPopup.alert({
title: 'Error In Getting Location',
tempdate:"Location auto detect failed. Please start GPS or wireless or mobile network location access service. And then try again"
});
}; // var geoerror
// call laction finder
if (window.cordova && navigator.geolocation) {
cordova.plugins.diagnostic.isLocationEnabled(function(enabled){
if(enabled){
alert("Before navigator");
navigator.geolocation.getCurrentPosition(geoSuccess,geoError,geooption);
alert("after navigator");
}
else{
alert("GPS off");
}
});
//navigator.geolocation.getCurrentPosition(geoSuccess,geoError,geooption);
}
else{
alert("window.cordova not support");
}
} // fun set location
}
})
Controller.js
$scope.getUserLocation = function(){
//$ionicPopup.confirm()
var confirmShareLocation = $ionicPopup.confirm({
title: ‘Title’,
template: ‘Would Like to Use Your Current Location ?’,
cancelText :“Don’t Allow”,
okText :‘OK’,
});
confirmShareLocation.then(function(res) {
if(res) {
//alert(" Allow ");
UserLocation.setlocation();
//console.log("IS Set :"+UserLocation.getlocationset());
//alert("in Controller Latitude ="+UserLocation.getlatitude()+"Longitude ="+UserLocation.getlongitude();
} else {
alert(" Don't Allow ");
}
});
};
Html file
< button class=“btn-filter” ng-click=“getUserLocation()” >Distance</button>
Can anyone help me on this?
Regards,