javaandroidmarkermapactivity

How can I add lines and buttons to a marker?


I am trying to display some information when the user clicks on a marker using the snippet of Marker class. As far as I know, the problem is that it can be only 1 line long, so I can't add a new line to make the information clearer. Is there any way to display more than one single line?
I'm using default MapActivity and googleMap API V2
Thank you in advance for your patience and consideration.


Solution

  • You can create custom info window. Take a look this dock https://developers.google.com/maps/documentation/android-sdk/infowindows#custom_info_windows

    Adapter example:

    public class CustomInfoWindow implements GoogleMap.InfoWindowAdapter {
        Context context; 
        LayoutInflater inflater;
        public CustomInfoWindow(Context context) {
               this.context = context;
        }
        @Override    
        public View getInfoContents(Marker marker) {        
            return null;    
        }
        @Override
        public View getInfoWindow(Marker marker) {
        inflater = (LayoutInflater)
    context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
    
       // R.layout.custom_info_window is a layout
       // res/layout folder. You can provide your own
        View v = inflater.inflate(R.layout.custom_info_window, null);   
    
        TextView title = (TextView) v.findViewById(R.id.info_window_title);     
      TextView subtitle = (TextView) v.findViewById(R.id.info_window_subtitle);
        title.setText(marker.getTitle());
        subtitle.setText(marker.getSnippet());
        return v;
        }
    }
    

    And for use it you need to make: map.setInfoWindowAdapter(new CustomInfoWindow(context));