我正在使用watchPosition方法连续获取坐标。我在showLocation方法中获得了纬度和经度。现在,我想将所有获取的纬度和经度存储到数据库中,因此我在showLocation方法中编写了db.transcation。现在如何从showLocation方法到populateDB方法获取动态纬度和经度。我想存储每次更改的经度和纬度。
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
var db = window.openDatabase("GPS", "1.0", "Simple GPS", 500000); //will create database GPS or open it
function onDeviceReady()
{
var watchID = null;
if(navigator.geolocation)
{
var options = { timeout: 5000, enableHighAccuracy: true };
watchID = navigator.geolocation.watchPosition(showLocation, errorHandler, options);
}
}
function populateDB(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS location (id INTEGER PRIMARY KEY AUTOINCREMENT, latitude TEXT, longitude TEXT, LastModifiedTime CHAR(30))');
tx.executeSql('INSERT INTO location(latitude,longitude,LastModifiedTime) VALUES ("-----", "------", datetime('now'))');
}
function showLocation(position)
{
// Getting Lat/Longs from call back method
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
// Display coordinates in html / screen..
document.getElementById("demo").innerHTML="<p>Latitude : " + latitude + "</p><p> Longitude: " + longitude +"</p>";
document.getElementById("messageTxt").innerHTML="Latitude : " + latitude + " Longitude: " + longitude;
document.getElementById("MailLatlongs").innerHTML="Latitude : " + latitude + " Longitude: " + longitude;
db.transaction(populateDB, errorCB, successCB);
}
</script>
最佳答案
我认为您想在事务回调函数中传递参数。
如果这是您的问题,请参考此链接。
how can I pass argument in transaction callback function