這裏的問題是我從數據庫中獲取經緯度信息,並在信息窗口的Google地圖上繪製多段線,它可以很好地處理標記。但是,即使我已經設置了位置,信息窗口也會出現在Google地圖上。 我已經使用的代碼如下: -如何在Google Map中的折線上方顯示信息窗口?
<script type="text/javascript">
function initialize()
{
var map;
var markers = JSON.parse('<%=ConvertDataTabletoString() %>');
var infoWindow = new google.maps.InfoWindow({maxWidth:200,minWidth:200});
var marker;
var x=new google.maps.LatLng(16.697000,74.244000);
var stavanger=new google.maps.LatLng(markers[0].lat1, markers[0].lng1);
var london=new google.maps.LatLng(markers[0].lat, markers[0].lng);
var j=0;
var i=0;
var points=new Array();
var points2=new Array();
var mapProp = {
center:new google.maps.LatLng(markers[0].lat, markers[0].lng),
zoom:14,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("map_canvas"),mapProp);
google.maps.event.addListener(map, "click", function(event)
{
var marker = new google.maps.Marker({
position: event.latLng,
animation: google.maps.Animation.DROP,
map: map
});
document.getElementById("txttolat").value = event.latLng.lat();
document.getElementById("txttolong").value = event.latLng.lng();
var pt=event.latLng.lat();
points[j]=event.latLng.lat();
points2[j]=event.latLng.lng();
j=j+1;
document.getElementById("txtlat").value = points[0];
document.getElementById("txtlong").value = points2[0];
// });
});
for (i = 0; i < markers.length; i++) {
var data = markers[i]
var stavanger2=new google.maps.LatLng(markers[i].lat1, markers[i].lng1);
var london2=new google.maps.LatLng(markers[i].lat, markers[i].lng);
var myTrip=[stavanger2,london2];
var flightPath=new google.maps.Polyline({
path:myTrip,
strokeColor:"#0000FF",
strokeOpacity:0.8,
strokeWeight:10,
map: map,
title: data.title
});
// }
(function(flightPath, data) {
google.maps.event.addListener(flightPath, 'click', function(e) {
// alert('you clicked polyline');
infoWindow.setContent(data.description);
infoWindow.open(map,flightPath);
infoWindow.setPosition(e.latLng);
document.getElementById("txtname").value = data.title;
document.getElementById("txtlat").value = e.latLng.lat();
document.getElementById("txtlong").value = e.latLng.lng();
});
})(flightPath, data);
}
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
嘿謝謝,但它仍然顯示我相同的結果,也關閉按鈕不顯示在InfoWindow上,我真的不明白該怎麼辦? – Priyanka
在jsbin –
上更新了示例嘿非常感謝您,我非常感謝您爲此示例花了一些時間。謝謝 :) – Priyanka