Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maximize infowindow with google map api v3

with google maps API v2 we can maximize the infowindow by specifying maxTitle property. Can anyone show me how we can maximize the infowindow with v3 of google map api.

Thanks

like image 347
Peacemoon Avatar asked Oct 16 '10 10:10

Peacemoon


1 Answers

I do not think there is yet an official way in version 3 to maximise Google Maps info windows as you could with version 2.

However you can acheive something similar, see code below. I am sorry my example code isn't very generic - if you require multiple markers you will need to re-write my code to use arrays or object literals or something.

<!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>

I hope this helps!

like image 191
Mark McLaren Avatar answered Nov 09 '22 18:11

Mark McLaren