How to use OnMarkerClickListener

2019-07-19 14:45发布

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?

2条回答
Root(大扎)
2楼-- · 2019-07-19 15:02

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);
    }
查看更多
聊天终结者
3楼-- · 2019-07-19 15:08

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

}
查看更多
登录 后发表回答