简体   繁体   中英

Google Maps Marker doesn't show with List<LatLng>

I do not understand why the map does not create marker using a List<LatLng> as follows:

protected void updateMapContents() {
 mGoogleMap.clear();
 if(myList.getList() != null && myList.getList().length > 0) {
     LatLngBounds.Builder builder = new LatLngBounds.Builder();
     for (int i = 0; i < myList.getList().size(); i++) {
         mGoogleMap.addMarker(new MarkerOptions().position(myList.getList().get(i)));
         builder.include(myList.getList().get(i));
         Log.e("Position List:", " " + i + myList.getList().get(i));
     }
     LatLngBounds bounds = builder.build();
     int padding = 0;
     CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, padding);
     mGoogleMap.moveCamera(cameraUpdate);
 }
}

This is logcat message:

E/Position List:: 0 lat/lng: (44.49,11.34)

The strange thing is that it all works with single marker, with array of LatLng also, I can not explain why with List this happens.

I've missed a check in onMapReady() method, so if I work with List it doesn't call updateMapContents()

That's all.

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