English 中文(简体)
自动打开 Google 地图信息窗口
原标题:Automatically opening Google maps infowindow

我有一张带有InfoWindow 的地图。 我需要在页面加载时打开这个InfoWindow。 在 API 中有一个 < code> InfoWindow. Open 方法, 但效果不好 。

这是我目前的代码

<html>
<head>
<link rel="stylesheet" href="/static/css/map.css" />
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script>
        var infoWindow = null;
        var map = null;
        var marker;
        function getInfoWindowEvent(marker, content) {
            infoWindow.close()
            infoWindow.setContent(content);
            infoWindow.open(map, marker);
        }
        function initialiseMap() {
            infoWindow = new google.maps.InfoWindow();
            var myLatlng = new google.maps.LatLng({MAP_6_LATITUDE}, {MAP_6_LONGTITUDE});
            var myOptions = {
                  zoom: 12,
                  streetViewControl: false,
                  center: myLatlng,
                  mapTypeId: google.maps.MapTypeId.ROADMAP
            }
            map = new google.maps.Map(document.getElementById("map_side_canvas"), myOptions);
            var bounds = new google.maps.LatLngBounds();
            var image = new google.maps.MarkerImage(
                 /static/img/markers/image.png ,
                new google.maps.Size(32,37),
                new google.maps.Point(0,0),
                new google.maps.Point(16,37)
            );

            var shadow = new google.maps.MarkerImage(
                 /static/img/markers/shadow.png ,
                new google.maps.Size(54,37),
                new google.maps.Point(0,0),
                new google.maps.Point(16,37)
            );

            var shape = {
                coord: [29,0,30,1,31,2,31,3,31,4,31,5,31,6,31,7,31,8,31,9,31,10,31,11,31,12,31,13,31,14,31,15,31,16,31,17,31,18,31,19,31,20,31,21,31,22,31,23,31,24,31,25,31,26,31,27,31,28,31,29,30,30,29,31,23,32,22,33,21,34,20,35,19,36,12,36,11,35,10,34,9,33,8,32,2,31,1,30,0,29,0,28,0,27,0,26,0,25,0,24,0,23,0,22,0,21,0,20,0,19,0,18,0,17,0,16,0,15,0,14,0,13,0,12,0,11,0,10,0,9,0,8,0,7,0,6,0,5,0,4,0,3,0,2,1,1,2,0,29,0],
                type:  poly 
            };

            var myLatlng = new google.maps.LatLng({MAP_6_LATITUDE}, {MAP_6_LONGTITUDE});
            marker = new google.maps.Marker({
                  position: myLatlng, 
                  map: map, 
                  icon: image,
                  shadow: shadow,
                  shape: shape,
                  title:"{TITLE}"
            });
            google.maps.event.addListener(marker,  click , function() {
            getInfoWindowEvent(marker, "<a href= {LINK} ><img src= /system/scripts/i.php?f={MAIN_PHOTO_21}&w=90&h=70&crop=1  class= hotel-img ></a><div class= rating  data-rate_level= {STARS_52} ></div><br /><a href= {LINK} ><h3>{TITLE}</h3></a><div class= price >From <div class= text ><?=number_format($minprice[0][0],0, , ,   ); ?> USD</div></div>");
            });
    infoWindow.open(map);
    return map;
        }
    </script>
</head>
<body onLoad="initialiseMap(); "  id="map_side_canvas" style="margin:0;padding:0;width:100%;height:100%;">
</body>

问题回答
function initialiseMap() {
  function getInfoWindowEvent(marker, content) {

你为什么有两个固定的功能?


我在第一个函数中看到您调用 InfoWindow. close () 。 这将从 DOM 中删除信息窗口。 然后您必须用 new google.maps. infowindow ( & lt; params>); 重新创建信息窗口





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.