【发布时间】:2015-09-15 09:13:24
【问题描述】:
我已经在 php.ini 中获取了所有 gps 设备的纬度和经度。我想要的是在 php 中,这个纬度和经度每 30 秒更新一次。更新值后,我想根据这些值更新标记位置。我为此挠了挠头,但每次我一起进入 ajax、javascript 和 php 时,这些事情都让我感到困惑。我的代码是:-
$returned_content=get_data($value->URL."&sDate=".$sdate."&eDate=".$edate);
//url gives the latitude and longitude
$xmlObj = simplexml_load_string($returned_content);
$json=$xmlObj->GetGPSData;
error_log($json);
$json_decode=json_decode($json);
foreach($json_decode as $row){
$lat_d= $row->Latitude;
echo("\n");
$long_d= $row->Longitude;
}
<html>
<head>
<?php
// <meta http-equiv="refresh" content="40" />
?>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api
/js?sensor=false"></script>
<script type="text/javascript">
var map;
function initialize() {
xar latlng = new google.maps.LatLng(<?php echo $lat_d; ?>, <?php echo $long_d; ?>);
var myOptions = {
zoom: 16,
center: latlng,
panControl: true,
zoomControl: true,
scaleControl: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
<?php
echo "addMarker(new google.maps.LatLng(".$lat_d.", ".$long_d."), map);";
?>
}
var icon = new google.maps.MarkerImage(
"http://4vector.com/i/free-vector-yellow-bus-clip-art_109340_Yellow_Bus_clip_art_hight.png",
null, //size is determined at RUNTIME
null, // origin is 0,0
null, // anchor is bottom center of the scaled image
new google.maps.Size(62,22)
);
function addMarker(latLng, map) {
var marker = new google.maps.Marker({
position: latLng,
map: map,
icon: icon,
draggable: true, // enables drag & drop
animation: google.maps.Animation.DROP
});
return marker;
}
</script>
</head>
<body onload="initialize()">
<div style="float:left; position:relative; width:550px; border:0px #000 solid;">
<div id="map_canvas" style="width:1421px;height:700px;border:solid black 1px;"></div>
</div>
</body>
</html>
我会非常感谢能帮助我的人。因为它现在在我头顶
【问题讨论】:
-
如果您想每 30 秒更新一次地图,您需要在 javascript 中完成所有位置收集,或者将 AJAX 接口写入 php 脚本,您可以每 30 秒运行一次以收集位置并提供位置作为数据 (JSON) 到 javascript,以便您可以重新绘制标记
-
先生,我所有的代码都在一个页面中,所以我应该如何编写每 30 秒为我带来 php 值的 ajax 代码
-
研究,研究,研究
-
先生,每次我这样做时,都会加载整个页面,但我想加载纬度和经度的值,然后只更新地图标记。我已经做了足够的搜索,但我无法理解我将如何使用此流程更新标记
-
那么你应该考虑付钱给能理解这个过程的人。它不是您试图让某人为您做的一件微不足道的编码。 SO 不是免费的编码资源
标签: javascript php google-maps google-maps-api-3