我有一个 android 应用程序在 1 秒内发送 gps 坐标。间隔到 php,然后是服务器上的 mysql。他们我有一个网站,可以在谷歌地图上实时跟踪设备的位置。问题是,当我调用 php 脚本在 mysql 中查询新坐标时,它第一次运行完美,并为我提供了在谷歌地图上使用的最新坐标,但在第一次循环之后,它继续给我相同的值,即使数据库已更新。
<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
?>
我在警报()中得到相同的结果;作为第一个查询,即使我向数据库添加行