I finished an app that use geoloc function. I’ve the problem that appear popup message confirmation that request access to position where there is the /var/mobile/Applications//Documents/index.html.
How solve this problem?
How check if cordova plugins are on?
Thx
Could you post a screenshot of said popup?
I don’t know with cordova geolocation, but when you work with the navigator geolocation (HTML5), on mobile there is no need to ask the user for permission. Just works if the GPS is On, or fails if its off.
Hey sorry for not understanding 100% what you mean, but I think you’re asking how to remove the app file location form the alert title?
If so, use the cordova dialog plugin
http://plugins.cordova.io/#/package/org.apache.cordova.dialogs
This is the screen:
this is the script to check if device is ready, but I think that it starts after angularjs/ionic…I get GEOposition to change background like ionic weather app.
<script>
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log("deviceready now");
alert("onDeviceReady");
navigator.geolocation.getCurrentPosition(onSuccess, onError);
$ionicPlatform.detect();
//if (parseFloat(window.device.version) === 7.0) {
// document.body.style.marginTop = "20px";
//}
};
function onSuccess(position) {
// your callback here
};
function onError(error) {
// your callback here
};
</script>
I see if I comment this code into my factory module that message disappear. I think because it execuded before Cordova device ready event. I’ve already added geo plugin.
getLocation: function() {
var q = $q.defer();
navigator.geolocation.getCurrentPosition(function(position) {
q.resolve(position);
}, function(error) {
q.reject(error);
console.log("Errore posizione " + error.code + "-" + error.message );
});
return q.promise;
}
How solve? You can see this issue into your https://github.com/driftyco/ionic-weather/ app.
Have someone the same problem? I think that ‘deviceready’ event start after controller/directives.
hey, have you found a fix for that? I’m running into the same problem right now for days and I can’t figure it out
Please reply if you got something
Hi, not at the moment. I’ve not try again until now.
I don’t get the second alert popup (just the first one which is clean) as you have mentioned (i.e. no index.html in popup)
controller.js
16 .controller('FriendsCtrl', function($scope, $ionicPlatform, $cordovaGeolocation, Friends) {
17 $scope.friends = Friends.all();
18
19 console.log("hi:hi");
20 // geolocation [wip]
21 $ionicPlatform.ready(function() {
22 //document.addEventListener("deviceready", function () {
23 console.log("now ready");
24 var posOptions = {timeout: 10000, enableHighAccuracy: false};
25 $cordovaGeolocation
26 .getCurrentPosition(posOptions)
27 .then(function (position) {
28 $scope.lat = position.coords.latitude
29 $scope.long = position.coords.longitude
30
31 // alert($scope.lat);
32 }, function(err) {
33 console.log("Error occurred!");
34 });
35 // }, false);
36 });
37 })
tabs-friends.html (used lat and long here)
1 <ion-view view-title="Friends">
2 <ion-content>
3 <ion-list>
4 <ion-item class="item-avatar" ng-repeat="friend in friends" type="item-text-wrap" href="#/tab/friend/{{friend.id}}">
5 <img ng-src="{{friend.face}}">
6 <h2>{{friend.name}}</h2><h3>{{lat}}</h3><h3>{{long}}</h3>
7 </ion-item>
8 </ion-list>
9 </ion-content>
10 </ion-view>
for the sake of completion:
sudo npm install -g cordova ionic
cordova plugin add org.apache.cordova.geolocation
ionic platform rm ios (necessary)
ionic platform add ios
ionic build ios
ionic emulate ios
To make it work, I had to do this a couple of times:
IOS simulator --> Reset content and Settings..
However I do get second popup if I put some ugly code like this in the controller.js:
alert($scope.lat);
Ionic view on iphone does not support cordova geolocation so, it didnt work there.
thats my real location, do not bomb me!
I’ve answered this on my own topic, you can’t call navigator inside your controller, you have to call it inside your app.js inside $ionicPlatform.ready(function() {
That will make the ugly pop up dissapear. I hope it gets fixed
Where do you have this information from @betoharres ? You can call $ionicPlatform.ready()
from anywhere, as it is described in the docs - http://ionicframework.com/docs/api/utility/ionic.Platform/
It basically works like the deviceready listener, only that it is also triggered when working in the desktop browser emulator. And of course you can also call navigator in the controller, or service or whereever in your JS code.
THX for your share of this question
Hi did you find a solution for this in the end?
Thanks
Same. Adding NSLocationWhenInUseUsageDescription string to AppName-Info.plist just gets cleared out when I run ionic build ios.
Hi,
I get that message too, but ONLY when I use Ionic View.
When I deploy to my iphone 5 it works fine and I only get the first (normal) dialog.
I added the cordova-plugin-dialogs and I am using $ionicPlatform.ready from my controllers.js …
Hi,
I’m getting the same alert with the message: " “/var/mobile/Containers/…/…/” Would Like To Use Your Current Location ", and I found some tips but, none works well. I saw something like:
Add these keys to ${PROJECT_NAME}-Info.plist
NSLocationWhenInUseUsageDescription, NSLocationUsageDescription and NSLocationAlwaysUsageDescription
But I had no success yet. Someone can help us?
Thanks
I get the following error with the cordova diagnostics plugin. Any ideas please?
hi @phanthinh, did you find solution for this issue. Please let me know.