Google Maps mehrer Infoboxn gleichzeitig anzeigen

KarlPichler

Mitglied
Hallo liebes Forum,

Frage. Ich habe mir für meine HP ein kleines snippet bzg. Google maps runtergeladen. ***** auch alles wunderbar, allerdings möchte ich das alle Infoboxn bei "OnLoad" angezeigt werden.

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: Common Loader</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">

function initialize() {
/**
  * map
  */
  var myLatlng = new google.maps.LatLng(39.980278, 4.049835);
  var myOptions = {
    zoom: 4,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    scrollwheel: false
  }
 var map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);

 var infoWindow = new google.maps.InfoWindow();
 var markerBounds = new google.maps.LatLngBounds();
 var markerArray = [];

 function makeMarker(options){
   var pushPin = new google.maps.Marker({map:map});
   pushPin.setOptions(options);
   google.maps.event.addListener(pushPin, 'click', function(){
     infoWindow.setOptions(options);
     infoWindow.open(map, pushPin);
   });
   markerArray.push(pushPin);
   return pushPin;
 }

 google.maps.event.addListener(map, 'click', function(){
   infoWindow.close();
 });

 function openMarker(i){
   google.maps.event.trigger(markerArray[i],'click');
 };

 /**
 *markers
 */
 makeMarker({
   position: new google.maps.LatLng(39.943962, 3.891220),
   title: '0',
   content: '<div>bla bla<div>'
 });
 
 makeMarker({
   position: new google.maps.LatLng(29.943962, 3.891220),
   title: '1',
   content: '<div>bla bla 2<div>'
 });
 
openMarker(0);
openMarker(1); //es öffnet sich ledlich der letzte aufgerufene Marker
}

</script>
</head>
<body onload="initialize()">
  <div id="map_canvas" style="width:400px; height:300px"></div>
</body>
</html>

Hat jemand einen Tipp? würdet mir sehr viel weiterhelfen. thx
Lg
 
Wenn du mehrere InfoWindow's gleichzeitig offen haben willst, benötigst du mehrere Instanzen eines google.maps.InfoWindow

Mögliche Herangehensweise:
Code:
 function makeMarker(options){
   var pushPin = new google.maps.Marker({map:map});
   pushPin.setOptions(options);
   //InfoWindow-instance als Eigenschaft des Markers speichern
   pushPin.set('infoWin',new google.maps.InfoWindow({content:options.content}));
   //handler zum Öffnen
   google.maps.event.addListener(pushPin, 'click', function(){
     this.get('infoWin').open(this.getMap(),this);
   });
   //handler zum Schliessen
   google.maps.event.addListener(map, 'click', function(){
     pushPin.get('infoWin').close();
   });
   markerArray.push(pushPin);
   return pushPin;
 }
 

Neue Beiträge

Zurück