Search code examples
androidgoogle-maps-markersgoogle-maps-api-2

How to use OnMarkerClickListener


I'm trying to make an application that allows to open new activity from a marker on the map with the method GoogleMap.OnMarkerClickListener but do not know how to use it. Does anyone help me?


Solution

  • Just use this:

    getMap().setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
    
            public void onInfoWindowClick(Marker marker) {
                Intent i = new Intent(getActivity(), NewActivity.class);
                startActivity(i);
    
            }
        });
    

    I used this code in my custom class that extends MapFragment I've placed it in this method:

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
    
    }