新手在这里。我正在开发一个在地图上显示车辆位置的程序。#Google 地图 API V3。该程序将自动从 sql server (live) 接收经度、纬度、速度、日期等信息。我希望地图显示所有标记(可用的 long 和 lat),并在每次特定标记的位置发生变化时更新标记的位置。更新包括每个标记的信息窗口。我的问题是启动程序时地图上没有显示标记(收到纬度和经度)。下面是代码:
var map = null;
var Table_Pins = {}; // Liste des Pins affichées
var Pos_Info = null; // Dit sur quel marker se situe l'infobulle
var Liste_Points = []; // Pour la mémorisation du tracé
var route = null;
var markers = [];
//-----------------------------------------------------------------
function initialize() {
var mapOptions = {
zoom: 15,
center: new google.maps.LatLng(43.665, 7.052),
mapTypeId: google.maps.MapTypeId.ROADMAP, //Type de carte
mapTypeControl: true,
panControl: true,
zoomControl: true, //Zoom
scaleControl: true, //Echelle
scaleControlOptions: {
position: google.maps.ControlPosition.LEFT_BOTTOM},
streetViewControl: true
} ;
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
Affiche_Pin(map, myPin);
}
//------------------------
// Ouverture du WebBrowser
// -----------------------
try { google.maps.event.addDomListener(window, 'load', initialize);}
catch (ex){ alert("vous devez etre connecte a l'internet...");}
// ------------------------------------------------------------------------------------
// Affichage des véhicules
// ------------------------------------------------------------------------------------
var myPin =[];
function Affiche_Pin(Lat, Long, immat, type, site, vitesse, date)
{
myPin = Table_Pins[immat];
if (typeof myPin != "undefined")
{
myPin.setPosition(new google.maps.LatLng(Lat, Long))
// La Pin est déja placée, on la déplace
// -------------------------------------
map = new google.maps.Map(document.getElementById('map'));
map.setCenter(new google.maps.LatLng(Lat, Long));
map.setZoom(15);
map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
if (Pos_Info == myPin) {
var infowindow = new google.maps.InfoWindow({
content: myPin.html,
position: new google.maps.LatLng(Lat, Long) });
infowindow.open(map);
} //end if (pos_info)
}//end if (mypin)
else{
var imageMarqueur = new google.maps.MarkerImage('http://maps.google.com/mapfiles/kml/pal4/icon15.png',
new google.maps.Size(32, 32),
new google.maps.Point(0,0),
new google.maps.Point(16, 32));
var ombreMarqueur = new google.maps.MarkerImage('http://maps.google.com/mapfiles/kml/pal4/icon15s.png',
new google.maps.Size(56, 32),
new google.maps.Point(0,0),
new google.maps.Point(16, 32));
var vehlatlng = new google.maps.LatLng(Lat, Long) ;
var marker = new google.maps.Marker({
map: map,
position: vehlatlng,
icon: imageMarqueur,
shadow: ombreMarqueur });
var infowindow = new google.maps.InfoWindow({
content: 'Véhicule :' + immat + ' ' + '<br>' +
'Site : ' + site + '<br>' +
'Type : ' + type + '<br>' +
'Vitesse : ' + vitesse + ' km/h' + '<br>' +
'Date : ' + date + '<br>',
position: vehlatlng });
}//end else
// Evenement "Click" et "infowindowopen" du marker
// ---------------------------
google.maps.event.addListener(marker, 'click', function() {
if(lastOpenInfoWin) lastOpenInfoWin.close();
lastOpenInfoWin = infowindow;
infowindow.open(marker.get('map'), marker);
Pos_Info = marker;});
Table_Pins[immat] = marker;
markers.push(marker);
marker.setMap(map);
}//end function affiche_pin
“immat”是车辆的id,“vitesse”是速度。提前致谢。