I am trying to add multiple markers in GoogleMaps. I am using Google SupportMapFragment. Onload my Map should show multiple markers based on data in arraylist however it shows only one marker. I have researched on this and i saw this question on SO but i do not why there is only one marker showing on map.
Update i debugged my code and realized that in this line
mMap.addMarker(new MarkerOptions().position(position));
only one position is getting passed before this line all data was being passed
Here is my code for same
@Override
public void onMapReady(GoogleMap googleMap) {
this.mMap = googleMap;
// Add a marker in Sydney, Australia,
// and move the map's camera to the same location.
// LatLng sydney = new LatLng(19.2372, 72.8441);
for(int i=0;i<providers.size();i++){
NearbyDataProvider provider = providers.get(i);
LatLng position = new LatLng(Double.parseDouble(provider.getLattitude())
,Double.parseDouble(provider.getLongitude()));
mMap.addMarker(new MarkerOptions().position(position));
mMap.moveCamera(CameraUpdateFactory.newLatLng(position));
}
}
NearByDataProvider.class
public class NearbyDataProvider { int image; String place; String lattitude; String longitude;
public NearbyDataProvider(int image, String place, String lattitude, String longitude) { this.setImage(image); this.setPlace(place); this.setLattitude(lattitude); this.setLongitude(longitude); } public int getImage() { return image; } public void setImage(int image) { this.image = image; } public String getPlace() { return place; } public void setPlace(String place) { this.place = place; } public String getLattitude() { return lattitude; } public void setLattitude(String lattitude) { this.lattitude = lattitude; } public String getLongitude() { return longitude; } public void setLongitude(String longitude) { this.longitude = longitude; } }
LatLong to be passed
private String[] latitude = {"19.2372","19.1998","19.1802","19.1551","19.1405"};
private String[] longitude = {"72.8441","72.8426","72.8554","72.8679","72.8422"};