Hey Doc,
This is how I just fixed it.
Add this to your config.xml per (https://cordova.apache.org/docs/en/3.0.0/cordova_geolocation_geolocation.md.html)
remove the plugin and install from git per http://stackoverflow.com/questions/24392943/cordova-geolocation-issues-in-ios-8-beta-2
ionic plugin rm cordova-plugin-geolocation
ionic plugin add GitHub - apache/cordova-plugin-geolocation: Apache Cordova Geolocation Plugin
Make sure you set up your google api key and enable the services.
Then, you’ve got to add an event listener or you’ll get a nasty warning as the app opens.
document.addEventListener(“deviceready”, onDeviceReady, false);
function onDeviceReady() {
console.log(“navigator.geolocation works well”);
}
Last note. If you want to do testing in the browser you’ll need to check if your using a device or the browser or you’ll get nothing but a white screen.
Here’s it all together:
//Browser
if(!(ionic.Platform.isIOS() || ionic.Platform.isAndroid())) {
var options = {timeout: 10000, enableHighAccuracy: true};
$cordovaGeolocation.getCurrentPosition(options).then(function (position) {
console.log(position);
var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var mapOptions = {
center: latLng,
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
$scope.map = new google.maps.Map(document.getElementById("map"), mapOptions);
//Wait until the map is loaded
google.maps.event.addListenerOnce($scope.map, 'idle', function () {
var marker = new google.maps.Marker({
map: $scope.map,
animation: google.maps.Animation.DROP,
position: latLng
});
var infoWindow = new google.maps.InfoWindow({
content: "Here I am!"
});
google.maps.event.addListener(marker, 'click', function () {
infoWindow.open($scope.map, marker);
});
});
})
}
//Native
else {
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log("navigator.geolocation works well");
var options = {timeout: 10000, enableHighAccuracy: true};
$cordovaGeolocation.getCurrentPosition(options).then(function (position) {
console.log(position);
var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var mapOptions = {
center: latLng,
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
$scope.map = new google.maps.Map(document.getElementById("map"), mapOptions);
//Wait until the map is loaded
google.maps.event.addListenerOnce($scope.map, 'idle', function () {
var marker = new google.maps.Marker({
map: $scope.map,
animation: google.maps.Animation.DROP,
position: latLng
});
var infoWindow = new google.maps.InfoWindow({
content: "Here I am!"
});
google.maps.event.addListener(marker, 'click', function () {
infoWindow.open($scope.map, marker);
});
});
}, function (error) {
console.log("Could not get location");
console.log(error);
});
}
}
Hope this helps.
Note: I just took a look into this further and found that ionic.Platform.ready() might be a better way to check than onDeviceReady(). You should be able to get rid of the check if it’s a browser or not.