2013-05-20 95 views
0

我嘗試使用jquery mobile with phonegap開發應用程序。在首頁寄存器號碼被輸入,然後使用表位獲取GPS值,然後更新其位置到SQLite數據庫。因爲我嘗試使用clearwatch()方法停止表位。我有以下錯誤。 遺漏的類型錯誤:對象#有沒有方法 'clearwatch' 我的index.htmlUncaught TypeError:Object#<Geolocation> has no method'clearwatch'

<!Doctype html> 
<html> 

<head> 
    <title>Geo position Aware Vehicle Locator</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"/> 
    <script src="js/jquery-1.9.0.min.js"></script> 
    <link rel="stylesheet" href="css/jquery.mobile-1.3.0-rc.1.min.css"/> 
    <script src="js/jquery.mobile-1.3.0-rc.1.min.js"></script> 
    <script src="js/register.js"></script> 
    <script src="js/terminate.js"></script> 
    <script src="js/update.js"></script> 
    <script> 
     document.addEventListener("deviceready", onDeviceReady, false); 

     function onDeviceReady() { 
      navigator.notification.alert("PhoneGap is ready!"); 
     } 
     $(document).ready(function() { 
      $("#regis").click(register); 
      $("#start").click(update); 
     }); 
    </script> 
</head> 

<body> 
<div data-role="page" data-theme="b"> 
    <div data-role="header" data-theme="b"> 
     <p align="center">Vehicle Registration</a> 
    </div> 
    <div data-role="content" data-theme="b"> 
     <label>Give Route Number</label> 
     <input type="text" id="rno"> <a href="#second" id="regis" data-transition="pop" data-role="button" 
             data-inline="true" data-icon="arrow-r" data-iconpos="right" data-mini="true" 
             data-theme="b">Register</a> 

    </div> 
</div> 
<div id="second" data-role="page" data-theme="b"> 
    <div data-role="header" data-theme="b"> 
     <p align="center">Vehicle Status</p> 
    </div> 
    <div data-role="content" data-theme="b"> 
     <div class="ui-bar-c ui-corner-all ui-shadow" style="padding:1em;"> 
      <h1>Current Location:</h1> 

      <h3> Latitude:</h3> 

      <p id="lat"></p> 

      <h3>Longitude:</h3> 

      <p id="long"></p> 

      <h3>Current Time:</h3> 

      <p id="utime"></p> <a id="start" data-role="button" data-theme="b">start</a> 
      <a id="terminate" data-role="button" data-icon="delete" data-iconpos="right" data-theme="b">Terminate</a> 
     </div> 
    </div> 
</div> 
</body> 

</html> 

和我terminate.js

document.addEventListener("deviceready", function() { 
    console.log("devicere"); 
    if (navigator.network.connection.type == Connection.NONE) { 
     console.log("check con"); 
     $("#terminate").text('No Internet Access') 
      .attr("data-icon", "delete") 
      .button('refresh'); 
    } 

}); 

var rno = localStorage.getItem('rno');//get value from local storage 
console.log("rno=>", rno); 
var watch_id = ''; // ID of the geolocation 
var tracking_data = []; // Array containing GPS position objects 
$("#start").on('click', function() { 
    watch_id = navigator.geolocation.watchPosition(
     // Success 
     function (position) { 
      console.log(position); 
      var lat = position.coords.latitude; 
      console.log("lat", lat); 
      var lon = position.coords.longitude; 
      console.log("lon", lon); 
      var utime = position.timestamp; 
      console.log("position", utime); 
      $("#lat").html(lat); 
      $("#long").html(lon); 
      $('#utime').html(utime); 
      console.log('position' + lat + lon + utime); 
      $.ajax({ 
       type: "POST", 
       url: "/update", 
       data: 'vid=' + rno + '&lat=' + lat + '&lon=' + lon + '&utime=' + utime, 
       cache: false 
      }); 
     }, 

     // Error 
     function (error) { 
      console.log(error); 
     }, 
     // Settings 
     { frequency: 3000, enableHighAccuracy: true }); 
}); 

//stop tracking gps value 
$("#terminate").on('click', function() { 
    navigator.geolocation.clearwatch(watch_id); 
    var url = "/terminate"; 
    $(location).attr('href', url); 

}); 

回答

0

應該navigator.geolocation.clearWatch(watch_id);在Watch中有一個大寫字母「W」。

相關問題