If you want to put multiple marker on google map, then just follow some snip of code below and enjoy it.
// Initialize variables
// Add Multiple marker on Map
// If you want to get particular marker click
// Initialize variables
private GoogleMap mMap;
private HashMap<Marker, Integer> mHashMap = new HashMap<Marker, Integer>();
private ArrayList<My_Custom_Model_Class> myList = new ArrayList<My_Custom_Model_Class>();
// Add Multiple marker on Map
for (int i = 0; i < myList.size(); i++) {
double latitude = myList.getLatitude();
double longitude = myList.getLongitude();
Marker marker = mMap.addMarker(new MarkerOptions().position(new LatLng(latitude,longitude))).title(myList.getTitle())
.icon(BitmapDescriptorFactory.fromResource(R.drawable.location_icon));
mHashMap.put(marker, i);
}
// If you want to get particular marker click
@Override
public boolean onMarkerClick(Marker marker) {
int pos = mHashMap.get(marker);
Log.i("Position of arraylist", pos+"");
}
Comments
Post a Comment