Adding multiple markers in Google Maps API v2 Android

Solution 1:

ArrayList<MarkerData> markersArray = new ArrayList<MarkerData>();

for(int i = 0 ; i < markersArray.size() ; i++) {

    createMarker(markersArray.get(i).getLatitude(), markersArray.get(i).getLongitude(), markersArray.get(i).getTitle(), markersArray.get(i).getSnippet(), markersArray.get(i).getIconResID());
}


protected Marker createMarker(double latitude, double longitude, String title, String snippet, int iconResID) {

    return googleMap.addMarker(new MarkerOptions()
            .position(new LatLng(latitude, longitude))
            .anchor(0.5f, 0.5f)
            .title(title)
            .snippet(snippet)
            .icon(BitmapDescriptorFactory.fromResource(iconResID)));
}

Solution 2:

Use MarkerOptions

private GoogleMap googleMap;
private MarkerOptions options = new MarkerOptions();
private ArrayList<LatLng> latlngs = new ArrayList<>();

You can add to the list of latlngs by,

 latlngs.add(new LatLng(12.334343, 33.43434)); //some latitude and logitude value

And then, use for loop to set them on the map.

 for (LatLng point : latlngs) {
     options.position(point);
     options.title("someTitle");
     options.snippet("someDesc");
     googleMap.addMarker(options);
 }