Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google maps open info window by default?

The following example shows a simple Marker (standard icon) on Google maps for the location and when clicking the icon, it opens the info window. Can I show the info window open by default so that I don't need to click the icon to open?

var myLatlng = new google.maps.LatLng(-25.363882,131.044922);     var myOptions = {     zoom: 4,     center: myLatlng,     mapTypeId: google.maps.MapTypeId.ROADMAP     }      var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);      var contentString = '<div id="content">'+         '<div id="siteNotice">'+         '</div>'+         '<h2 id="firstHeading" class="firstHeading">Uluru</h2>'+         '</div>';      var infowindow = new google.maps.InfoWindow({         content: contentString     });      var marker = new google.maps.Marker({         position: myLatlng,         map: map,         title:"Uluru (Ayers Rock)"     });      google.maps.event.addListener(marker, 'click', function() {     infowindow.open(map,marker);     }); 
like image 438
Billa Avatar asked Nov 23 '11 08:11

Billa


People also ask

How do I open the information window in Google Maps?

Open an info window To make the info window visible, you must call the open() method on the InfoWindow , passing an InfoWindowOpenOptions object literal specifying the following options: map specifies the map or Street View panorama on which to open. anchor contains an anchor point (for example a Marker ).

How do I customize the Google Maps window pop up?

You can modify the whole InfoWindow using jquery alone... var popup = new google. maps. InfoWindow({ content:'<p id="hook">Hello World!

How do I get rid of InfoWindow in Google Maps?

After constructing an InfoWindow, you must call open to display it on the map. The user can click the close button on the InfoWindow to remove it from the map, or the developer can call close() for the same effect.

How do I know if InfoWindow is open?

Calling InfoWindow. getOpenedState() returns a boolean which reflects the state (opened/closed) of the infowindow.


1 Answers

If you want to show the info window opened by default without click, just add a new code like bellow:

Your code:

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

So we have a new code like this:

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

As you can see, we just add a little line code with infowindow.open(map,marker);

like image 185
Idham Perdameian Avatar answered Sep 18 '22 11:09

Idham Perdameian