更新标记,而无需重新加载网页google maps v3
首先,我为我的英语不好而道歉,但是我在所有法语论坛上都找不到我的问题的答案.
First of all I apologize for my poor English but I can not find the answer to my question on all French forums.
我正在开发一个应用程序,用于实时跟踪车队.
I am developing an application that is to make real-time tracking of a fleet of vehicles.
我正在本应用程序的结尾,但是我有一个问题.不重新加载网页就无法更新标记.
I'm at the end of this application but I have a problem. I can not update my markers without reloading my web page.
我尝试使用settimeout()
,但它仍在为我的地图收费
I tried with settimeout()
but it still charging my map
这是我的代码,谢谢您的帮助.
here is my code thank you for your help.
ps:完成后,此应用程序将在开源中可用
ps: when completed this application will be available in open source
<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>
您必须请求一个资源(可能是PHP脚本),该资源使用AJAX返回标记(tableauLieux)的数据.
You'll have to request a ressource(may be a PHP-script) which returns the data for the markers(tableauLieux) using AJAX.
获得响应后,请删除当前标记并创建新标记.
Once you got the response, remove the current markers and create the new markers.