我为卡车停在的位置创建了停止点标记。但是当点击所有停止点时,我需要一些帮助来打开infowindow。
我的js代码:
var ImageStop = '/images/StopPoint.gif';
var infoWindowTrcukStop = new google.maps.InfoWindow();
var json = result.d;
obj = JSON.parse(json);
for (var i = 0; i < obj.length - 1; i++)
{
if(parseInt(obj[i].Speed)==0)
{
var LatLngStop = new google.maps.LatLng(obj[i].Lat, obj[i].Lng);
markerStopTruck = new google.maps.Marker({
position: LatLngStop,
draggable: true,
animation: google.maps.Animation.DROP,
map: map,
title: 'Stopped Here',
icon: ImageStop,
});
google.maps.event.addListener(markerStopTruck, 'click', function (e) {
infoWindowTruckStop.setContent(this.title);
infoWindowTruckStop.open(map, markerStopTruck);
});
markerStopTruck.setMap(map);
}
}
答案 0 :(得分:0)
我解决了。
for (var i = 0; i < obj.length - 1; i++) {
if(parseInt(obj[i].Hiz)==0) {
var LatLngStop = new google.maps.LatLng(obj[i].Lat, obj[i].Lng);
markerStopTruck= new google.maps.Marker({
position: LatLngStop,
draggable: true,
animation: google.maps.Animation.DROP,
map: map,
title: '',
icon: ImageStop,
});
var content = 'Stop Here';
google.maps.event.addListener(markerStopTruck, 'click', (function
(markerStopTruck, content, infoWindowTruckStop) {
return function () {
infoWindowTruckStop.setContent(content);
infoWindowTruckStop.open(map, markerStopTruck);
};
})(markerStopTruck, content, infoWindowTruckStop));
markerStopTruck.setMap(map);
} }