Emulator to find current user location?

Hi,

Would it be possible to get current location with emulator ios?

navigator.geolocation code that I have to find location is not working only for emulator.

In the iOS Simulator, you can go to Debug -> Location in the menu bar and set the location. They actually have a bunch of different options to simulate movement too.

I think this is causing problem where

navigator.geolocation.getCurrentPosition(getCurrLocSuccess, getCurrLocError);
$ionicLoading.show(…);

I have loading that started after geolocation and .hide() as getCurrLocSuccess or getCurrLocError is called.

That is still happening after Debug → Location set location.

Are you running the geolocation query after onDeviceReady fires?

I use the $cordovaGeolocation plugin which always works for me across the board.

@emily

After installing ngCordova, I am running below command, $cordovaGeolocation is load correctly(checked with logging). Howerver, the $ionicLoading is never stopped since I have both call bak to call $ionicLoading.hide().

So, I belive the device is rejected calling getCurrentPostion?

How do I allow the emulator to actually call that function or allow user location usage?

$ionicPlatform.ready(function() {
			$cordovaGeolocation
			    .getCurrentPosition(posOptions)
			    .then(getCurrLocSuccess)
			    .catch(getCurrLocError);
			$ionicLoading.show({
	        	template: '<ion-spinner icon="ripple" class="spinner-energized"></ion-spinner>',
			    animation: 'fade-in',
			    showBackdrop: false,
			});
		});

I’ve got mine working with this way of error handling:

$cordovaGeolocation.getCurrentPosition(posOptions)   .then( function(position) {     // success code   }, function(err) {     // error code });

You also may want to call $ionicLoading.show() before the geolocation call (you can call that outside of $ionicPlatform.ready too).

Reason why I don’t use that way of error handling is reason below.

somePromise().then(function () {
  throw new Error('oh noes');
}).catch(function (err) {
  // I caught your error! :)
});

somePromise().then(function () {
  throw new Error('oh noes');
}, function (err) {
  // I didn't catch your error! :(
});

It won’t catch error that will occur in resolve handler with that “,”.

I also don’t want it to start #ionicLoading when its not $ionicPlatform.ready too.

I think this is just because I am running on emulator and trying to get current location… I am running it on a device right now to test it.

Thanks for your helps!