How to use OnMarkerClickListener

10,297

Solution 1

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) {

}

Solution 2

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

private GoogleMap mMap:

.....
protected void onCreate(Bundle savedInstanceState) {
.....

private void setUpMap() {
.....
mMap.setOnInfoWindowClickListener(this);

@Override
    public void onInfoWindowClick(Marker marker) {
        // When touch InfoWindow on the market, display another screen. 
        Intent intent = new Intent(this, Another.class);
        startActivity(intent);
    }
Share:
10,297
velas16v
Author by

velas16v

Updated on June 04, 2022

Comments

  • velas16v
    velas16v almost 2 years

    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?

  • dumazy
    dumazy over 11 years
    I'll make a blog post on the new Google Maps API v2 for Android somewhere tomorrow. check it at bon-app-etit.blogspot.com
  • Abraham Philip
    Abraham Philip about 9 years
    Shouldn't it be new Intent(CurrentActivity.this, Another.class); ?