使用谷歌地图api v3最大化infowindow

时间:2010-10-16 10:16:32

标签: google-maps google-maps-api-3

使用google maps API v2,我们可以通过指定maxTitle属性来最大化infowindow。任何人都可以告诉我如何使用google map api v3最大化infowindow。

由于

2 个答案:

答案 0 :(得分:3)

我认为版本3中还没有正式的方法来最大化Google地图信息窗口as you could with version 2

但是你可以实现类似的功能,请参阅下面的代码。对不起,我的示例代码不是很通用 - 如果您需要多个标记,则需要重新编写我的代码以使用数组或对象文字等。

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: Info Window Simple</title>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
  var contentString1 =
   "<a onclick=\"expand();\">+ Expand</a>";

  var contentString2 =
    "<div>" +
    "<a onclick=\"collapse();\">- Collapse</a>" +
    "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque consequat lacinia mi, sit amet aliquam sem interdum a. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Phasellus sed accumsan augue. Vivamus egestas nibh vel nulla mattis ut pulvinar tortor interdum. Quisque scelerisque, urna non vehicula porta, mi leo pellentesque arcu, non ullamcorper metus quam quis diam. Etiam quis nisl id tellus dictum semper at non mi. Praesent vel justo sed nisl cursus accumsan eu eget sem. Donec id lacus augue, nec vehicula metus. Maecenas varius ligula et orci mattis rhoncus. In interdum neque eu libero lobortis ac tristique metus fermentum. In eu turpis sit amet augue laoreet imperdiet.</p>" +
    "<p>Fusce molestie, nulla sit amet condimentum facilisis, augue elit tincidunt nisl, sit amet fermentum tellus tortor non sem. Etiam turpis lectus, fermentum ut congue vitae, gravida eget magna. Sed tristique, lacus a tincidunt faucibus, augue nulla aliquet ipsum, sagittis imperdiet nunc elit ac massa. Aliquam rutrum, urna quis accumsan suscipit, lectus massa rutrum velit, eget dignissim nisl orci a risus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec faucibus semper metus sit amet adipiscing. Donec consequat, est quis lacinia porta, eros magna tempor orci, ac suscipit sem justo vel enim. Suspendisse mauris nulla, pulvinar ac placerat vel, dignissim in tortor. Nunc arcu sapien, placerat id scelerisque porta, placerat vel neque. Morbi ut magna at risus varius interdum vitae ut lectus. Maecenas luctus rutrum augue. Phasellus facilisis, dui at ornare faucibus, mi magna iaculis nunc, in faucibus diam turpis vel sapien. Duis ac orci augue, vitae vehicula mauris. Curabitur sodales sem in lectus euismod tempus.</p>" +
    "<p>Suspendisse sagittis consectetur velit ut vulputate. Nullam ante odio, posuere sit amet dignissim vel, mollis eget nunc. Quisque fringilla tempus rutrum. Aenean hendrerit blandit ipsum, a blandit est volutpat sed. Etiam auctor erat ac nulla pellentesque vestibulum. Pellentesque congue justo ac massa aliquam vitae convallis velit condimentum. Ut aliquam posuere feugiat. In convallis vulputate tortor, nec ultrices enim ultrices non. Donec laoreet nibh at quam varius gravida. Donec massa nibh, cursus vel blandit sit amet, ultrices et turpis. Pellentesque adipiscing porta lorem, sit amet mollis augue posuere et. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Quisque eget tortor mauris. Praesent eu pulvinar tortor. Proin eleifend interdum massa, at ultrices ligula viverra a. In auctor velit lorem. Quisque et massa quis lacus cursus fringilla. Maecenas ut convallis lectus. In ac erat vestibulum enim porttitor scelerisque in quis lacus. Cras quis diam mauris. </p>" +
    "</div>";

  var infowindow;
  var map;
  var marker;

  function initialize() {
    var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
    var myOptions = {
      zoom: 4,
      center: myLatlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }

    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);


    infowindow = new google.maps.InfoWindow({
        content: contentString1
    });

    marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title: 'Test'
    });

    google.maps.event.addListener(marker, 'click', function() {
      infowindow.open(map,marker);
    });

    google.maps.event.addListener(infowindow, 'click', function() {
      infowindow.open(map,marker);
    });


  }

  function expand(){
    infowindow.close();
    infowindow.setContent(contentString2);
    infowindow.open(map, marker);
  }

  function collapse(){
    infowindow.setContent(contentString1);
  }

</script>
</head>
<body onload="initialize()">
  <div id="map_canvas"></div>
</body>

</html>

我希望这有帮助!

答案 1 :(得分:0)

Apparently this guy知道该怎么做,但他不会说:P

修改

嗨Kirk,

我的book中的第146-150页对此进行了描述。

感谢阅读!

祝你好运, 加布里埃尔斯文纳伯格 - -
你的V3书的哪一页在你提到的http://see.weareinto.com/3syJ时提到MapBlowup?