0

I have the coordinates of my markers in a LatLng arraylist. I add all the markers to a marker arraylist.

for(int i=0; i<markers_location.length; i++){
    coords_markers.add(new LatLng(lat_markers.get(i), lon_markers.get(i)));}

List<Marker> markers = new ArrayList<>();
for(int i=0; i<markers_location.length; i++){
    Marker marker = mMap.addMarker(new MarkerOptions().position(coords_markers.get(i)));
    markers.add(marker);
}

How can I then add these markers to the map? I tried this:

mMap.addMarker(markers.get(0));

But it doesn't work.

3
  • What do you mean by "it doesn't work"? Commented Feb 11, 2017 at 14:11
  • 3
    you have already added the marker when you called mMap.addMarker in your for loop. Commented Feb 11, 2017 at 14:14
  • You are right, I already added it at the for loop. I was just confused because I needed the marker arraylist to change all the markericons on zoom change. Commented Feb 11, 2017 at 14:33

1 Answer 1

1

Try this:

for(int i=0; i<markers_location.length; i++){
coords_markers.add(new LatLng(
lat_markers.get(i).getLatitude, 
lon_markers.get(i).getLongitude));}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.