0

I'm writing an app that keeps track of your position while running. The issue is that I can only start/stop the tracking only once. I have to kill the app to restore functionality.

$("#startRunning").live('click', function () 
{
    watch_id = navigator.geolocation.watchPosition( function (position) 
    {
        tracking_data.push(position);
        element.innerHTML = 'Aantal metingen: ' + aantalMeetingen;    
    },
    function (error) 
    {    
        console.log(error);  
    },
    {   
        enableHighAccuracy: true, maximumAge: 5000, timeout: 7000, 
    });

    track_id = loopNummer;
});

$("#stopRunning").live('click', function () 
{
    window.localStorage.setItem(track_id, JSON.stringify(tracking_data));
    alert(watch_id);

    //Reset the values and clearWatch
    navigator.geolocation.clearWatch(watch_id);
    aantalMeetingen = 0;
    watch_id = null;
    tracking_data = null;
    showResult();
});

I have no I idea how to fix this issue, because my code (should) be working normally.

6
  • If this is something you're writing now, you should stay away from methods that have been deprecated for some time, like live(). Commented May 12, 2013 at 18:33
  • And what do you suggest as alternative? $("lllelel").click(function()) ? Commented May 12, 2013 at 18:35
  • Just replacing live() with on()? Gonna try that, 1 moment Commented May 12, 2013 at 18:36
  • The syntax is different! Commented May 12, 2013 at 18:36
  • Do you declare any of those variables somewhere, or are they just implied to exist, and all global ? Commented May 12, 2013 at 18:40

1 Answer 1

2

Just a guess, but instead of

tracking_data = null;

try

tracking_data = [];

otherwise tracking_data.push(position); is bound to cause a null pointer error.

Let me know :)

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks man, that solved it. I never thought of it. Great work!
np ;) A decent debugger would've told you the same though. Might be worth investing in..
I was thinking about doing that. Which one do you suggst/use yourself?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.