$cordovageolocation timeout on route change

Hi,

I have a directive set up which uses the watchPosition() function from $cordovageolocation and then displays a google map with the user’s position plotted on it. This works fine, but if I leave the route with $state.go I am finding strange results. $state.go goes to ‘app.jobs.search’ :

If I leave with $state.go, then use the ionic back button which calls $ionicGoBack(), the directive is still displayed fine

  1. The problem I have is that I need to send some params back to the original view, so on the search route, I then do:

$ionicHistory.backView().stateParams = {jobCode:jobCode};
$ionicHistory.goBack();

I am then returned to the main jobs page, but the geolocation timesout. If I remove the top line of then it continues to display OK, as though I’ve pressed the $ionicGoBack() button.

Does anyone have any ideas how I can fix this? Thanks in advance for any help

codePen would be helpful to assist you with the problem

Hi Aaron,

Here’s a simplified codepen of my problem http://codepen.io/anon/pen/zGJRQg

If you click the ‘search for a job code’ button, it takes you to the search page. When you’re on this page, if you click the back button in the top left corner, the map on the first page still displays OK. However if you click the ‘select job code’ button, you are redirected back to the original page but the map isn’t visible.

Hope that makes sense.

I’ve removed $cordovaGeolocation from the codepen and set my own position and the problem still exists so I guess the problem is more related to how I’ve set up the directive rather than the ngCordova library