Skip to content

Commit fcb88c6

Browse files
committed
Don't fit to elements if no positions added
1 parent 6d2804e commit fcb88c6

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

android/src/main/java/com/airbnb/android/react/maps/AirMapView.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -497,20 +497,27 @@ public void animateToCoordinate(LatLng coordinate, int duration) {
497497

498498
public void fitToElements(boolean animated) {
499499
LatLngBounds.Builder builder = new LatLngBounds.Builder();
500+
501+
boolean addedPosition = false;
502+
500503
for (AirMapFeature feature : features) {
501504
if (feature instanceof AirMapMarker) {
502505
Marker marker = (Marker) feature.getFeature();
503506
builder.include(marker.getPosition());
507+
addedPosition = true;
504508
}
505509
// TODO(lmr): may want to include shapes / etc.
506510
}
507-
LatLngBounds bounds = builder.build();
508-
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 50);
509-
if (animated) {
510-
startMonitoringRegion();
511-
map.animateCamera(cu);
512-
} else {
513-
map.moveCamera(cu);
511+
512+
if (addedPosition) {
513+
LatLngBounds bounds = builder.build();
514+
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 50);
515+
if (animated) {
516+
startMonitoringRegion();
517+
map.animateCamera(cu);
518+
} else {
519+
map.moveCamera(cu);
520+
}
514521
}
515522
}
516523

0 commit comments

Comments
 (0)