Skip to content Skip to sidebar Skip to footer

How To Open A Infowindow On Every Marker (multiple Marker) In Android?

Since I am using Google map v2 and I want to open info window on multiple makers. I have done this with single marker, and also used show info window(); but it works in on last mar

Solution 1:

The default markers can only show one info window at a time. However, you can easily show more, using the Maps Android library: https://developers.google.com/maps/documentation/android-api/utility/

Here is an example:

IconGeneratoriconFactory=newIconGenerator(this);
mMarkerA = mMap.addMarker(newMarkerOptions().position(newLatLng(12, 34)));
mMarkerA.setIcon(BitmapDescriptorFactory.fromBitmap(iconFactory.makeIcon("Marker A")));
mMarkerB = mMap.addMarker(newMarkerOptions().position(newLatLng(13, 35)));
mMarkerB.setIcon(BitmapDescriptorFactory.fromBitmap(iconFactory.makeIcon("Marker B")));

And add

compile'com.google.maps.android:android-maps-utils:0.4+'

to your gradle file.

Solution 2:

According to Google Maps Android v2

An info window allows you to display information to the user when they tap on a marker on a map. By default, an info window is displayed when a user taps on a marker if the marker has a title set. Only one info window is displayed at a time. If a user clicks on another marker, the current window will be hidden and the new info window will be displayed. You can show an info window programmatically by calling showInfoWindow() on the target marker. An info window can be hidden by calling hideInfoWindow()

do like:

 LatLng latlang = new LatLng(lati, longi);
    if (map != null) {
    Marker marker = map.addMarker(new MarkerOptions()
    .position(latlang)
    .title(getResources().getString(R.string.titleProduct))
    .snippet(getResources().getString(R.string.contentProduct))
    .icon(BitmapDescriptorFactory
    .fromResource(R.drawable.map_pointer)));
     marker.showInfoWindow();

}

and repeat this same with as much as you have map pointers.

Solution 3:

First comment this line.

googleMap.setInfoWindowAdapter(newCustomInfoWindowAdapter());

then add markers on map using this code

Marker marker = googleMap.addMarker(new MarkerOptions()
                 .position(HAMBURG)
                 .title("Hamburg")
                 .snippet("welcome to Map")
                 .icon(BitmapDescriptorFactory.fromResource(R.drawable.start_pin)).draggable(false));
  googleMap.addMarker(new MarkerOptions()
                 .position(KIEL)
                 .title("KIEL")
                 .snippet("welcome to Map")
                 .icon(BitmapDescriptorFactory.fromResource(R.drawable.start_pin)).draggable(false));

marker.showInfoWindow();

then comment the other code and execute it once. Then i will give CustomAdapter code

Post a Comment for "How To Open A Infowindow On Every Marker (multiple Marker) In Android?"