Google maps api 3 在不重新加载网页的情况下更新标记google maps v3
首先,我为我糟糕的英语道歉,但是我在所有的法语论坛上都找不到我问题的答案 我正在开发一个应用程序,用于实时跟踪车队 我已经申请完了,但我有个问题。我无法在不重新加载网页的情况下更新标记 我尝试了Google maps api 3 在不重新加载网页的情况下更新标记google maps v3,google-maps-api-3,Google Maps Api 3,首先,我为我糟糕的英语道歉,但是我在所有的法语论坛上都找不到我问题的答案 我正在开发一个应用程序,用于实时跟踪车队 我已经申请完了,但我有个问题。我无法在不重新加载网页的情况下更新标记 我尝试了settimeout(),但它仍在向我的地图收费 这是我的密码谢谢你的帮助 ps:完成后,此应用程序将以开源形式提供 <html lang="fr"> <head> <link rel="stylesheet" media="screen" type=
settimeout()
,但它仍在向我的地图收费
这是我的密码谢谢你的帮助
ps:完成后,此应用程序将以开源形式提供
<html lang="fr">
<head>
<link rel="stylesheet" media="screen" type="text/css" title="Exemple" href="theme.css"/>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta charset="UTF-8" />
<title>Geonano V1</title>
<style type="text/css">
html{height: 100%}
body{height: 100%; margin: 0px; padding: 0px}
#EmplacementDeMaCarte{height: 100%}
</style>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialisation() {
var tableauLieux = [
//here I have a loop in php to get my markers in my database
["Paris", 48.86110, 2.34459],
["Versailles", 48.78199, 2.11045]
];
var optionsCarte = {
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var maCarte = new google.maps.Map(document.getElementById("EmplacementDeMaCarte"), optionsCarte);
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < tableauLieux.length; i++) {
var Lieu = tableauLieux[i];
var pointLieu = new google.maps.LatLng(Lieu[1], Lieu[2]);
bounds.extend(pointLieu);
var marqueurLieu = new google.maps.Marker({
position: pointLieu,
map: maCarte,
title: Lieu[0],
icon : Lieu[3],
clickable: true
});
//création de l'info-bulle
var infoBulle = new google.maps.InfoWindow({
content: Lieu[0]//ici on peut mettre des balises HTML
});
google.maps.event.addListener(marqueurLieu, 'click', function() {
infowindow.setContent(Lieu[i][0]);
infoBulle .open(maCarte,marqueurLieu);
});
}
maCarte.fitBounds(bounds);
}
google.maps.event.addDomListener(window, 'load', initialisation);
setInterval("initialisation()", 5000);
</script>
</head>
<body>
<div id="EmplacementDeMaCarte"></div>
</body>
<META HTTP-EQUIV="Refresh" CONTENT="120; URL=http://localhost/geonano.php">
</html>
Geonano V1
html{高度:100%}
正文{高度:100%;边距:0px;填充:0px}
#侵位数据点{高度:100%}
函数初始化(){
var tableauLieux=[
//这里我在php中有一个循环,用于在数据库中获取标记
[“巴黎”,48.86110,2.34459],
[《凡尔赛》,48.78199,2.11045]
];
var期权单={
mapTypeId:google.maps.mapTypeId.ROADMAP
};
var maCarte=new google.maps.Map(document.getElementById(“empositiondemacart”),optionscort);
var bounds=new google.maps.LatLngBounds();
对于(变量i=0;i
您必须请求一个ressource(可能是一个PHP脚本),它使用AJAX返回标记(tableauLieux)的数据
收到响应后,删除当前标记并创建新标记。您必须请求一个ressource(可能是PHP脚本),它使用AJAX返回标记(tableauLieux)的数据
收到响应后,删除当前标记并创建新标记。如果我理解正确,您将使用所有标记每隔5秒重新绘制地图 基本上,你要做的是将你的标记存储在一个数组中,你可以在以后循环通过它来改变它们的lat和lng。从地图上清除它们,更改信息,然后将它们放回地图上。更改信息需要一些ajax
marker.setMap(null);
如果我理解正确的话,你每5秒钟就用所有的标记重新绘制一次地图 基本上,你要做的是将你的标记存储在一个数组中,你可以在以后循环通过它来改变它们的lat和lng。从地图上清除它们,更改信息,然后将它们放回地图上。更改信息需要一些ajax
marker.setMap(null);
这样做的一个好方法是使用
refreshIntervalId = setInterval("requestPoints()", 4000);
function requestPoints() {
$.ajax({
url:'{% url 'gpstracking.ajax.request_tracks' %}',
type: 'get',
dataType: 'json',
data: {
vehicles: vehicles
},
success: function (positions) {
updatePoints (positions);
}
});
}
function updatePoints (positions) {
console.debug('updating markers');
var lttd;
var lgtd;
for (var i=0; i < positions.length; i++) {
lttd = positions[i].latitude;
lgtd = positions[i].longitude;
position = map.createPosition({
lat: lttd,
lng: lgtd,
});
markers[positions[i].registration].setPosition(position);
};
if (positions.length > 1) {
//map.fitZoom();
} else {
map.setCenter (lttd, lgtd);
}
}
refreshIntervalId=setInterval(“requestPoints()”,4000);
函数requestPoints(){
$.ajax({
url:“{%url”gpstracking.ajax.request_跟踪“%}”,
键入:“get”,
数据类型:“json”,
数据:{
车辆:车辆
},
成功:职能(职位){
更新点(位置);
}
});
}
函数更新点(位置){
调试('更新标记');
var-lttd;
var-lgtd;
对于(变量i=0;i1){
//fitZoom();
}否则{
map.setCenter(lttd、lgtd);
}
}
一个很好的方法是使用
refreshIntervalId = setInterval("requestPoints()", 4000);
function requestPoints() {
$.ajax({
url:'{% url 'gpstracking.ajax.request_tracks' %}',
type: 'get',
dataType: 'json',
data: {
vehicles: vehicles
},
success: function (positions) {
updatePoints (positions);
}
});
}
function updatePoints (positions) {
console.debug('updating markers');
var lttd;
var lgtd;
for (var i=0; i < positions.length; i++) {
lttd = positions[i].latitude;
lgtd = positions[i].longitude;
position = map.createPosition({
lat: lttd,
lng: lgtd,
});
markers[positions[i].registration].setPosition(position);
};
if (positions.length > 1) {
//map.fitZoom();
} else {
map.setCenter (lttd, lgtd);
}
}
refreshIntervalId=setInterval(“requestPoints()”,4000);
函数requestPoints(){
$.ajax({
url:“{%url”gpstracking.ajax.request_跟踪“%}”,
键入:“get”,
数据类型:“json”,
数据:{
车辆:车辆
},
成功:职能(职位){
更新点(位置);
}
});
}
函数更新点(位置){
调试('更新标记');
var-lttd;
var-lgtd;
对于(变量i=0;i1){
//fitZoom();
}否则{
map.setCenter(lttd、lgtd);
}
}
谢谢您的帮助我了解您的方法,但我无法在javascript中实现它。您能帮我吗?再次感谢您创建了一个函数,您每5秒钟调用一次该函数,该函数执行PHP循环以从数据库中获取标记。我认为清除之前的标记将是最好的。map.clearOverlays();然后像以前一样重新绘制标记。这样,您就不必保存它们,也不必进行更新