How to open multiple infowindows or multiple markers using GMAP2

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to open multiple infowindows or multiple markers using GMAP2

raju.ch
This post was updated on .
Hi,
Fairly new to the Google Maps Api. I've got an array of data that I want to cycle through and plot on a map. Seems fairly simple, but all the multi-marker tutorials I have found are quite complex.

Lets use the data array from google's site for an example:


  ['Bondi Beach', -33.890542, 151.274856, 4],
  ['Coogee Beach', -33.923036, 151.259052, 5],
  ['Cronulla Beach', -34.028249, 151.157507, 3],
  ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
  ['Maroubra Beach', -33.950198, 151.259302, 1]

I simply want to plot all of these points and have an infoWindow pop up when clicked to display the name.
and i've already tried with the Wicket Examples but not find a suitable one and i tried by creating multiple objects of GLatLng like below.
 new GLatLng( 48.1234, -120.1234 ),
    new GLatLng( 48.5678, -120.5678 ),
    new GLatLng( 48.9101, -120.9112 ),
    new GLatLng( 48.1121, -120.1314 ),
    new GLatLng( 48.3145, -120.1516 ),
    new GLatLng( 48.1617, -120.1718 ),
    new GLatLng( 48.1819, -120.1920 ),
    new GLatLng( 48.2021, -120.2122 )
Any help is greatly appreciated! and I want it like in the attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to open multiple infowindows or multiple markers using GMAP2

chrome1235
I think you can not do in gmap2, because of google map api (version2).
you can check this address.
http://code.google.com/apis/maps/documentation/javascript/v2/reference.html#GInfoWindow

Reply | Threaded
Open this post in threaded view
|

Re: How to open multiple infowindows or multiple markers using GMAP2

Gabriel Landon
In reply to this post by raju.ch
You can do something like that (pseudo code) :

//create marker
GMarker marker = new GMarker(new GLatLng(xx.xxx, xxx.xxx), new GMarkerOptions("Label to display on mouse hover", yourCustomIcon));

//add marker on the map
addOverlay(marker);

//add onClick event
add(new ClickListener() {
    @Override
    protected void onClick(final AjaxRequestTarget varTarget, final GLatLng varLatLng, final GOverlay varOverlay) {
    if (varOverlay instanceof Gmarker) {
        Gmarker marker = (Gmarker) varOverlay;
        //use any logic to get the data you want to display (using lat and long for example)
        MyData data = yourService.findData(marker.getLatLng());
               
        //open the infowindow
        getInfoWindow().open(marker, new yourPanelToDisplay(panelId, data));
    }
});

Hope this help.
Gabriel.