我在谷歌地图上自动显示我的gps坐标有问题。当我实现地图是静态的时候一切正常,但现在我动态地尝试它。这意味着当新的gps coord保存到数据库时,地图应该自动刷新。
我在一个.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>
....
在第一次刷新之前,我看到了Map和它上面的路径,一次刷新后我得到了这个错误:
警告:mysql_fetch_array()期望参数1是资源, 给出的布尔值 第4行的C:\ xampp \ htdocs \ Alt \ FIFA-Europaliga \ content \ show_runs.php
注意:未定义的变量:cords in 第8行的C:\ xampp \ htdocs \ Alt \ FIFA-Europaliga \ content \ show_runs.php
注意:未定义的偏移:1英寸 第9行的C:\ xampp \ htdocs \ Alt \ FIFA-Europaliga \ content \ show_runs.php
注意:未定义的变量:cords in 第11行的C:\ xampp \ htdocs \ Alt \ FIFA-Europaliga \ content \ show_runs.php
有人能帮助我吗?
答案 0 :(得分:0)
在运行查询之前,必须连接到服务器并选择数据库。
$db = mysql_connect('hostname|ip', 'user', 'password');
mysql_select_db('database_name', $db);
$result = mysql_query('SELECT ...', $db);
如果查询失败,mysql_query将返回false,这解释了关于期望资源和获取布尔值的错误。
关于需要资源的mysql_fetch_array的警告意味着查询失败。它可能失败的原因包括:
在所有情况下,您都可以通过打印mysql_error()
来检查错误。