代码只执行一次 - Phonegap&Javascript
问题描述:
我正在编写一个应用程序,用于在运行时跟踪您的位置。 问题是我只能启动/停止跟踪一次。我必须杀死应用才能恢复功能。代码只执行一次 - Phonegap&Javascript
$("#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();
});
我没有我的想法如何解决这个问题,因为我的代码(应该)工作正常。
如果这是你现在正在写,你应该远离已经过时了一段时间,像活的()方法远的东西。 – adeneo 2013-05-12 18:33:48
你有什么建议作为替代? $(“lllelel”)。click(function())? – Matt 2013-05-12 18:35:05
on()? – adeneo 2013-05-12 18:35:31