我无法在谷歌地图上自动显示我的 gps 坐标。当我实现地图是静态的时,一切正常,但现在我动态尝试。这意味着当一个新的 gps 坐标将被保存到数据库时,地图应该会自动刷新。
我在一个 .php 文件中实现了所有内容。要显示带有用户必须选择条目的坐标的地图,条目的链接如下所示 -> http://trackmyrun1.at/index.php?page=show_runs&data1=get&data2=1
<?php
$result = mysql_query("SELECT * FROM fifa_gps WHERE run_id=".$_GET['data2']."");
while ($line = mysql_fetch_array($result)) {
$cords[] = "new google.maps.LatLng(" . $line['lat'] . ", " . $line['longt'] . "),";
}
$cord_start = explode("(", $cords[0]);
$cord_pos_start = explode(")", $cord_start[1]);
$cord_end = explode("(", $cords[count($cords)-1]);
$cord_pos_end = explode(")", $cord_end[1]);
echo $sys->overall_distance($_GET['data2']);
?>
<div id="map-canvas" style="height:400px"/>
<script type="text/javascript">
var seconds = 1;
var divid = "map-canvas";
var url = "http://localhost/alt/FIFA-Europaliga/index.php?page=show_runs&data1=get&data2=<?php echo $_GET['data2']; ?>";
function refreshdiv(){
// The XMLHttpRequest object
var xmlHttp;
try{
xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("Your browser does not support AJAX.");
return false;
}
}
}
// Timestamp for preventing IE caching the GET request
fetch_unix_timestamp = function()
{
return parseInt(new Date().getTime().toString().substring(0, 10))
}
var timestamp = fetch_unix_timestamp();
var nocacheurl = url+"?t="+timestamp;
// The code...
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
document.getElementById(divid).innerHTML=xmlHttp.responseText;
setTimeout('refreshdiv()',seconds*1000);
}
}
xmlHttp.open("GET",nocacheurl,true);
xmlHttp.send(null);
}
// Start the refreshing process
var seconds;
window.onload = function startrefresh(){
setTimeout('refreshdiv()',seconds*1000);
}
<!--
refreshdiv();
// -->
</script>
<script type="text/javascript">
function initialize() {
var myLatLng = new google.maps.LatLng(<?php echo $cord_pos_start[0]; ?>);
var mapOptions = {
zoom: 15,
center: myLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
var flightPlanCoordinates = [
<?php echo implode('', $cords); ?>
];
var image_start = 'http://labs.google.com/ridefinder/images/mm_20_green.png';
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title:"Start",
icon: image_start
});
var image_end = 'http://labs.google.com/ridefinder/images/mm_20_red.png';
var endMarker = new google.maps.Marker({
position: new google.maps.LatLng(<?php echo $cord_pos_end[0]; ?>),
map: map,
title:"Ende",
icon: image_end
});
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
strokeColor: "#FF0000",
strokeOpacity: 0.5,
strokeWeight: 5
});
flightPath.setMap(map);
}
initialize();
</script>
....
在第一次刷新之前,我看到了地图和上面的路径,在一次刷新之后,我收到了这个错误:
警告:mysql_fetch_array() 期望参数 1 是资源,布尔值在第 4 行的 C:\xampp\htdocs\Alt\FIFA-Europaliga\content\show_runs.php 中给出
注意:未定义的变量:第 8 行 C:\xampp\htdocs\Alt\FIFA-Europaliga\content\show_runs.php 中的绳索
注意:未定义的偏移量:第 9 行 C:\xampp\htdocs\Alt\FIFA-Europaliga\content\show_runs.php 中的 1
注意:未定义变量:第 11 行 C:\xampp\htdocs\Alt\FIFA-Europaliga\content\show_runs.php 中的绳索
有人可以帮助我吗?