我在一个联系页面中使用了Google地图,并希望显示在Google地图上使用的信息窗口。请前往以下链接:Gmap,然后单击标记。应该会出现一个信息窗口。
我的问题是:如何在我的网站上实现同样的效果?PS:我知道如何构建google.maps.InfoWindow对象,但我不想自己创建HTML。
我的问题是:如何在我的网站上实现同样的效果?PS:我知道如何构建google.maps.InfoWindow对象,但我不想自己创建HTML。
var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var mapOptions = {
zoom: 4,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
初始化你的地图
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
设置您的信息窗口内容
var contentString = '<b>Set content for infowindow here in HTML<b>';
使用内容字符串初始化您的 infoWindow。
var infowindow = new google.maps.InfoWindow({
content: contentString
});
将您的标记放置在上面定义的地图上先前定义的标记处
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title:"Uluru (Ayers Rock)"
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});