1

I know there's a similar post about this, but the owner got it working just by reinstalling the plugin, which didn't work for me. Here's what I did:

$ ionic start mySecondApp tabs

$ cd mySecondApp

$ ionic platform add ios

$ cordova plugin add org.apache.cordova.geolocation

$ vim www/js/controller.js

**Insert this code at DashCtrl: **

.controller('DashCtrl', function($scope) {

  var onSuccess = function(position) {
    var lat       = position.coords.latitude;
    var lng       = position.coords.longitude;

   alert(lat +"\n" + lng);
  };
  // onError Callback receives a PositionError object
  //
  function onError(error) {
      alert('code: '    + error.code    + '\n' +
            'message: ' + error.message + '\n');
  }
  navigator.geolocation.getCurrentPosition(onSuccess, onError)

})

save it

$ ionic build ios

$ ionic emulate ios

First you will see the proper message that I want saying that your app wants to use your location, fine, then after that you will see this poping up:

Any idea how to fix this? I've tried ngcordova and doesn't work too

The same happens on the emulator

Here's the QR code if you want to use the ionic view

Or just download the project: here

betoharres
  • 1,736
  • 2
  • 19
  • 25

1 Answers1

1

just found the "solution" ( more like a workaround )

the answer is from StackOverflow: Location permission alert on iPhone with PhoneGap

You need to do the geolocation after the device is ready. The following Jquery code, for example, will geolocate without that nasty alert:

$(function(){
  document.addEventListener("deviceready", onDeviceReady, false);
})

function onDeviceReady() {
  navigator.geolocation.getCurrentPosition(onSuccess, onError);     
}

function onSuccess(position) {
  // your callback here 
}

function onError(error) { 
  // your callback here
}

In ionic you would put it insdie $ionicPlatform.ready(function() {

Community
  • 1
  • 1
betoharres
  • 1,736
  • 2
  • 19
  • 25