-1
我有一個android應用程序在1秒內發送GPS座標。間隔到php然後在服務器上的mysql。他們有一個網站,可以在Google地圖上實時跟蹤設備的位置。問題是,當我調用php腳本來查詢mysql中的新座標時,它第一次運行完美,並給我在谷歌地圖上使用的最新座標,但在第一次循環後,它繼續提供給我相同的值,即使數據庫已更新。實時mySQL,PHP谷歌地圖API更新
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Horse Tracker © 2013 Abiapps</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link type="text/css" href="style.css" rel="stylesheet" media="all" />
<script type="text/javascript"src="http://maps.google.com/maps/api/js?********&sensor=false"></script>
<script type="text/javascript" src="map.js"></script>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
</head>
<body>
<h1>Horse Tracker © 2013 Abiapps </h1>
<input type="button" value="getValues" id="getValues" />
<input type="button" value="changeValues" id="changeValues" />
<div id="map"></div>
<script>
(function() {
window.onload = function() {
var mapDiv = document.getElementById('map');
var latlng = new google.maps.LatLng(35.694094,23.683620);
var options = {
center: latlng,
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
navigationControl: true,
navigationControlOptions: {
position: google.maps.ControlPosition.TOP_RIGHT
},
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
},
streetViewControl: false,
backgroundColor: '#0000ff'
};
var map = new google.maps.Map(mapDiv, options);
document.getElementById('getValues').onclick = function() {
alert('Current Zoom level is ' + map.getZoom());
alert('Current center is ' + map.getCenter());
}
document.getElementById('changeValues').onclick = function() {
var latLng = new google.maps.LatLng(<?php include 'getgps.inc.php';?>);
map.setCenter(latLng);
}
var a = 1;
function autoUpdate() {
a = a;
var latLng = new google.maps.LatLng(<?php include 'getgps.inc.php';?>);
map.setCenter(latLng);
alert('<?php include 'getgps.inc.php';?>');
setTimeout(autoUpdate, 1000);
}
autoUpdate();
}
})();
</script>
</body>
</html>
和PHP代碼..
<?php
$host="localhost";
$username="*****";
$password="*****";
$db_name="horsetrack";
$tbl_name="gps"; //
$body = "";
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name ORDER BY id DESC LIMIT 1 ";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){
$id = $rows['id'];
$datetime = $rows["datetime"];
$Rname = $rows["rider"];
$Rlat = $rows["lat"];
$Rlng = $rows["lng"];
$body = $Rlat.','.$Rlng;
}
echo $body;
mysql_close(); //close database
?>
即時得到在警報)相同的結果(;作爲firt查詢,即使我向數據庫添加行
ajax上的任何好書籍,我可以讀? –
本網站有大量的Ajax問題/答案,以及大量的Googleable教程。 –