I searched various forums and posts related to GeoLocation based alert issue; For some reason no technique worked in my case.
Added "cordova-plugin-geolocation" plugin to my Ionic Framework Project.
Added to my base Controller under $ionicPlatform.ready(...)
navigator.geolocation.getCurrentPosition(function(position) {
var coords = {};
coords.updated = new Date();
coords.latitude = position.coords.latitude.toFixed(6);
coords.longitude = position.coords.longitude.toFixed(6);
coords.altitude = position.coords.altitude + ' m';
coords.accuracy = position.coords.accuracy + ' m';
coords.altitudeAccuracy = position.coords.altitudeAccuracy + ' m';
coords.heading = position.coords.heading + '\u00b0';
coords.speed = position.coords.speed + ' m/s';
console.log('Fetched Location...' + geoText);
return position;
}, function(err) {
Logger.error(err.message);
}, {
timeout: 10000,
enableHighAccuracy: true
});
When I emulate / run in iOS / Android it throws
Error Message: /www/index.html would like to use Your Location
I would greatly appreciate if someone can help.
Add these lines in config.xml
i have fixed this problem.
I resolved this issue by following this
Created a new Service for Location as follows
Then we shall call services as
within
$ionicPlatform.ready(..)
or add to a buttonng-click
to fetch location.Root Cause: What I believe is that when we call
Location.fetch()
ornavigator.geolocation..
directly in any controllers, its executed when the controllers are loaded initially. This might get fired before Cordova / Ionic platform is ready and hence we get the additional / unwanted alert mentioning that www/index.html is trying to use location as my problem states.