0

I want to build an interactive Android map app. It will have different marker types and lots of of different options when clicking on them.

First approach : I started with the notion I will use custom infowindows but figured out that a map can have only single InfoWindowAdapter, with that said, this approach has another fault. InfoWindows can't have click listeners registered to them and I need to have some clickable UI to show after marker click.

Second approach : Marker click triggers an alertDialog which corresponds to the marker type. I'm hesitant because I'll have lots of switch case inside the OnActivityResult. Example - dialog fragments with OnActivityResult

Any other ideas ? Am I missing something ?

Community
  • 1
  • 1
serj
  • 508
  • 4
  • 20

1 Answers1

1

I ran into similar problem some time ago and I "hacked" it as follows:

mGoogleMap.setInfoWindowAdapter(new InfoWindowAdapter() {
    @Override
    public View getInfoWindow(Marker pMarker) {
        MarkerDescriptor descriptor = mMarkerDescriptorsMap.get(pMarker);
        mGoogleMap.setOnInfoWindowClickListener(descriptor.getOnInfoWindowClickListener(MapActivity.this));     
        return descriptor.getInfoWindowView();
    }
}

MarkerDescriptor should be simple interface that will be implemented for each specific marker type:

public interface MarkerDescriptor {
    public View getInfoWindowView();
    public OnInfoWindowClickListener getOnInfoWindowClickListener(Context pContext);
}

And to keep the references:

private Map<Marker, MarkerDescriptor> mMarkerDescriptorsMap = new HashMap<Marker, MarkerDescriptor>();

Basics of this idea is that GoogleMap can have only one marker selected at the time, so when user chooses another marker, we change the listeners.

Nuwisam
  • 830
  • 6
  • 10
  • why pMarker.hideInfoWindow() ? – serj Dec 29 '14 at 15:01
  • 1
    This is part of my app logic - if there is no defined action asociated with this InfoWindow, just hide it. Sorry, I should have cutted it out from sample. – Nuwisam Dec 29 '14 at 15:03
  • So you switch the WindowInfoAdapter depending on the marker ? Does it hinder the performance ? – serj Dec 31 '14 at 08:12
  • 1
    To be precise I change OnInfoWindowClickListener depending on the marker. Basically setting listeners is just updating references - it affects perfromance equaly to `variable = someOtherVariable;`. – Nuwisam Dec 31 '14 at 17:12