简体   繁体   中英

Google map: onInfiWindowClickListener: INTENT

My codes seems to work fine. but when I run it. the intent activity always go on the last Intent. but I tap on different MARKS. Can someone know how to seperate the intent using .onInfowindowClickListener.

Marker celMarker = mMap.addMarker(new MarkerOptions()
        .position(new LatLng(14.212137, 120.968046))
        .title("Balinsasayaw")
        .snippet("Cuisine"));

celMarker.showInfoWindow();
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
    @Override
    public void onInfoWindowClick(Marker marker) {
        Intent intent = new Intent(Map2.this, Balinsasayaw.class);
        startActivity(intent);
    }
});


Marker chaMarker = mMap.addMarker(new MarkerOptions()
        .position(new LatLng(14.146741, 120.974217))
        .title("Balinsasayaw")
        .snippet("Cuisine"));

chaMarker.showInfoWindow();
mMap.setOnInfoWindowClickListener(new     GoogleMap.OnInfoWindowClickListener() {
    @Override
    public void onInfoWindowClick(Marker marker) {
        Intent intent = new Intent(Map2.this, Chateu.class);
        startActivity(intent);
    }
});

only use one OnInfoWindowClickListener and compare which marker was clicked

mMap.setOnInfoWindowClickListener(new     GoogleMap.OnInfoWindowClickListener() {
        @Override
        public void onInfoWindowClick(Marker marker) {
            if(marker.equals(celMarker)){
            Intent intent = new Intent(Map2.this, Balinsasayaw.class);
            startActivity(intent);

            }else if(marker.equals(chaMarker)){
            Intent intent = new Intent(Map2.this, Chateu.class);
            startActivity(intent);
            }
        }
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM