简体   繁体   中英

google maps API: how can I make markers clickable?

How can I make markers clickable? On clicking the markers, I need the app to navigate to a different activity. I have created some markers in a class by taking coordinates from an ArrayList. Every help is welcome.

import java.util.ArrayList;

public class Segnalini {

public static void POI(ArrayList<Mostro> Mostri, Marker[] M_Mostri, LatLng[] P_Mostri, GoogleMap Mappa){

    P_Mostri[0] = new LatLng(Mostri.get(0).Latitudine, Mostri.get(0).Longitudine);
    M_Mostri[0] = Mappa.addMarker(new MarkerOptions().position(P_Mostri[0]).title("M1"));

    P_Mostri[1] = new LatLng(Mostri.get(1).Latitudine, Mostri.get(1).Longitudine);
    M_Mostri[1] = Mappa.addMarker(new MarkerOptions().position(P_Mostri[1]).title("M2"));

    P_Mostri[2] = new LatLng(Mostri.get(2).Latitudine, Mostri.get(2).Longitudine);
    M_Mostri[2] = Mappa.addMarker(new MarkerOptions().position(P_Mostri[2]).title("M3"));

    P_Mostri[3] = new LatLng(Mostri.get(3).Latitudine, Mostri.get(3).Longitudine);
    M_Mostri[3] = Mappa.addMarker(new MarkerOptions().position(P_Mostri[3]).title("M4"));

    P_Mostri[4] = new LatLng(Mostri.get(4).Latitudine, Mostri.get(4).Longitudine);
    M_Mostri[4] = Mappa.addMarker(new MarkerOptions().position(P_Mostri[4]).title("M5"));

}
}

GoogleMap mMap = googleMap; // name of your map

mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
    @Override
    public boolean onMarkerClick(Marker marker) {
    // CONDITION WHEN CLICKED
    return false;
    }
    });

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