谷歌地图api - 打开第一个信息窗口

时间:2012-08-25 07:16:31

标签: google-maps-api-3

以下是在Google地图上添加infoWindows和标记的代码:

    infowindow = new google.maps.InfoWindow()
    createMarker = (company)->
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(company.latitude, company.longitude),
        map: map,
        title: company.name
      })

      google.maps.event.addListener(marker, 'click', ()->
        content = 'some content'
        infowindow.setContent(content)
        infowindow.open(map,this)
      )

    createMarker(data[i]) for i in [0..data.length-1] by 1

我需要在加载页面后自动打开infoWindow。我该怎么办?

1 个答案:

答案 0 :(得分:2)

发起一个事件:     google.maps.event.trigger(,'click');

现在,您需要存储对“marker”变量的引用。变化

marker = new google.maps.Marker({

company.marker = new google.maps.Marker({

并添加最后一行:

google.maps.event.trigger(data[0].marker, 'click');