Geolocation doesn't work while app starts


Hi, I need help with geolocation. After seraching and trying geolocation plugins (none of them works…) I decited to go with navigator.geolocation. At first it works but I delete tabs in my project and them my problem begin. My function should work if I’m in “dash” state and after every 10 seconds. Works for every 10 seconds but doesn’t work when app starts (and it start with “dash” state). This is my code (why code block doesnt work here on forum?):

function onSuccess(position) {
console.log(“It works!”);

function watch() {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
console.log(“Watch function is running”);
var interval=window.localStorage.getItem(‘interval’); // 10 000 (10 seconds)
$interval(watch, interval);

And here is part of my app.js:
.config(function($stateProvider, $urlRouterProvider) {


.state(‘dash’, {
url: ‘/dash’,
templateUrl: ‘templates/tab-dash.html’,
controller: ‘DashCtrl’