infowindow Android studio

1

I'm making an android application that has a map in which clicking on a marker shows the infowindow as follows:

my question is how do I add a different image to each marker and if it is possible as I call the images of a server as cloudinary to not store everything in the app, I am new to android. thanks

    
asked by Kyo Shiro 22.11.2016 в 19:58
source

1 answer

1

For this you have to create a% custom InfoWindowAdapter , containing the reference to ImageView and load the images from the resources, this is an example:

    public class CustomInfoWindowAdapter implements InfoWindowAdapter{

        private static final String TAG = "CustomInfoWindowAdapter";
        private LayoutInflater inflater;

        public CustomInfoWindowAdapter(LayoutInflater inflater){
            this.inflater = inflater;
        }

        @Override
        public View getInfoContents(final Marker m) {
            //Carga layout personalizado.
            View v = inflater.inflate(R.layout.infowindow_layout, null);       

             Drawable myDrawable = getResources().getDrawable(R.drawable.mi_imagen);                                                            
            //Carga imagen.   
            ((ImageView)v.findViewById(R.id.info_window_image)).setImageDrawable(myDrawable);
               ((TextView)v.findViewById(R.id.info_window_city)).setText("Sidney");
                ((TextView)v.findViewById(R.id.info_window_lat)).setText("-10.79");
                ((TextView)v.findViewById(R.id.info_window_lon)).setText("-77.71");      
                return v;
            }

            @Override
            public View getInfoWindow(Marker m) {
                return null;
            }        
        }

To load the custom infoWindow, you do it to your GoogleMap using the method setInfoWindowAdapter() where you assign the InfoWindowAdapter personalized.

myGoogleMap.setInfoWindowAdapter(new CustomInfoWindowAdapter(LayoutInflater.from(getActivity())));
    
answered by 22.11.2016 в 20:20