在标记的同时在Google地图中显示infoWindow

时间:2010-05-06 22:01:41

标签: javascript google-maps

我开发了一个谷歌地图页面,显示我告诉它的标记。如果单击marketr,则会弹出infoWindow。但是,我想知道是否有人知道如何打开infoWindow并同时显示标记? (如在上载中)

以下是页面:http://www.sportingemporium.com/map_test3.htm

这似乎是一个简单的练习,但我已经搜索了几个小时而没有找到解决方案!

任何帮助都会很棒!

2 个答案:

答案 0 :(得分:3)

您只需要致电marker.openInfoWindowHtml()以强制打开信息窗口:

var map = new GMap2(document.getElementById("map"));
var point = new GLatLng(53.3407791, -6.2596385);

map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(point, 16);

// Set up three markers with info windows 
var html = 'South Anne Street,<br />Dublin 2, Ireland';
var marker = new GMarker(point);

map.addOverlay(marker);
marker.openInfoWindowHtml(html);     // This opens the info window automatically

GEvent.addListener(marker, "click", function() {
   marker.openInfoWindowHtml(html);
});

openInfoWindowHtml http://img534.imageshack.us/img534/1273/autoinfo.png

答案 1 :(得分:0)

这是代码! ...正如你所看到的那样,页面加载块已经被GUnload()占用了吗?还有其他地方可以进行那次调用吗?

<script type="text/javascript">
//<![CDATA[

if (GBrowserIsCompatible()) { 

  function createMarker(point,html) {
    var marker = new GMarker(point);
    GEvent.addListener(marker, "click", function() {
      marker.openInfoWindowHtml(html);
    });
    return marker;
  }

  // Display the map, with some controls and set the initial location 
  var map = new GMap2(document.getElementById("map"));
  map.addControl(new GLargeMapControl());
  map.addControl(new GMapTypeControl());
  map.setCenter(new GLatLng(53.3407791,-6.2596385),16);

  // Set up three markers with info windows 

  var point = new GLatLng(53.3407791,-6.2596385);
  var marker = createMarker(point,'<img src="images/casino-on-map.jpg" width="125" height="125" hspace="10" align="left"><strong>The Sporting Emporium</strong><br/><p>Annes Lane, <br />South Anne Street,<br />Dublin 2, Ireland<br /><br />(+353 1) 7030 600<br /><a href="mailto:info@thesportingemporium.com">info@thesportingemporium.com</a></p>')
  map.addOverlay(marker);

}

// display a warning if the browser was not compatible
else {
  alert("Sorry, the Google Maps API is not compatible with this browser");
}

//]]>
</script>