views:

77

answers:

1

For simplicity sake, lets use the XML example on Econym's site.

http://econym.org.uk/gmap/example_map3.htm

Once clicked, I would like icon balloon to be displayed in the middle of the map.

What might I need to add to Mike's code to get this to work? I apologize for asking a lot..

Thanks in advance.

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

    if (GBrowserIsCompatible()) {
side_bar
      var side_bar_html = "";


      var gmarkers = [];


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

        gmarkers.push(marker);

        side_bar_html += '<a href="javascript:myclick(' + (gmarkers.length-1) + ')">' + name + '<\/a><br>';
        return marker;
      }



      function myclick(i) {
        GEvent.trigger(gmarkers[i], "click");
      }



      var map = new GMap2(document.getElementById("map"));
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
      map.setCenter(new GLatLng( 43.907787,-79.359741), 9);



      GDownloadUrl("example.xml", function(doc) {
        var xmlDoc = GXml.parse(doc);
        var markers = xmlDoc.documentElement.getElementsByTagName("marker");

        for (var i = 0; i < markers.length; i++) {
          // obtain the attribues of each marker
          var lat = parseFloat(markers[i].getAttribute("lat"));
          var lng = parseFloat(markers[i].getAttribute("lng"));
          var point = new GLatLng(lat,lng);
          var html = markers[i].getAttribute("html");
          var label = markers[i].getAttribute("label");

          var marker = createMarker(point,label,html);
          map.addOverlay(marker);
        }

        document.getElementById("side_bar").innerHTML = side_bar_html;
      });
    }

    else {
      alert("Sorry, the Google Maps API is not compatible with this browser");
    }


    //]]>
    </script>
+1  A: 

What you are looking to use is the GMap2.setCenter()(Google API Documentation) function.

So, you should be able to use it as follows:

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

You could, of course, change the order of those actions to your taste.

Lucanos