3

我在联系页面中有一个 Goole 地图,我想在其中显示 Google 地图上使用的 infoWindow。

转到该链接:Gmap

并单击标记。应该会出现一个信息窗口。

我的问题是:如何在我的网站上添加相同的内容?

Ps:我知道如何构建 google.maps.InfoWindow 对象,但我不想自己创建 html。

4

1 回答 1

0

谷歌地图文档的这一部分解释了这一点:https ://developers.google.com/maps/documentation/javascript/overlays#InfoWindows

定义您的经纬度坐标

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);

设置 infowWindow 的内容

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);
});
于 2012-11-05T14:26:30.490 回答