Google Maps Android API v2 - Interactive InfoWindow (like in original android google maps)

前端 未结 7 1777
眼角桃花
眼角桃花 2020-11-22 01:41

I am trying to a make custom InfoWindow after a click on a marker with the new Google Maps API v2. I want it to look like in the original maps application by Go

7条回答
  •  野的像风
    2020-11-22 02:25

    It is really simple.

    googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {
    
                // Use default InfoWindow frame
                @Override
                public View getInfoWindow(Marker marker) {              
                    return null;
                }           
    
                // Defines the contents of the InfoWindow
                @Override
                public View getInfoContents(Marker marker) {
    
                    // Getting view from the layout file info_window_layout
                    View v = getLayoutInflater().inflate(R.layout.info_window_layout, null);
    
                    // Getting reference to the TextView to set title
                    TextView note = (TextView) v.findViewById(R.id.note);
    
                    note.setText(marker.getTitle() );
    
                    // Returning the view containing InfoWindow contents
                    return v;
    
                }
    
            });
    

    Just add above code in your class where you are using GoogleMap. R.layout.info_window_layout is our custom layout that is showing the view that will come in place of infowindow. I just added the textview here. You can add additonal view here to make it like the sample snap. My info_window_layout was

    
    
    
            
    
    
    

    I hope it will help. We can find a working example of custom infowindow at http://wptrafficanalyzer.in/blog/customizing-infowindow-contents-in-google-map-android-api-v2-using-infowindowadapter/#comment-39731

    EDITED : This code is shows how we can add custom view on infoWindow. This code did not handle the clicks on Custom View items. So it is close to answer but not exactly the answer that's why It is not accepted as answer.

提交回复
热议问题