Skip to content Skip to sidebar Skip to footer

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 anyo

Solution 1:

Just use this:

getMap().setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

        publicvoidonInfoWindowClick(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:

@OverridepublicvoidonActivityCreated(Bundle savedInstanceState) {

}

Solution 2:

When touching Info window within a marker, if changing the current screen into another screen(class or Activity), Do this below;

privateGoogleMapmMap:

.....
protectedvoidonCreate(Bundle savedInstanceState) {
.....

privatevoidsetUpMap() {
.....
mMap.setOnInfoWindowClickListener(this);

@OverridepublicvoidonInfoWindowClick(Marker marker) {
        // When touch InfoWindow on the market, display another screen. Intent intent = newIntent(this, Another.class);
        startActivity(intent);
    }

Post a Comment for "How To Use Onmarkerclicklistener"