我正在編寫一個應用程序,用於在運行時跟蹤您的位置。 問題是我只能啓動/停止跟蹤一次。我必須殺死應用才能恢復功能。代碼只執行一次 - 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