Skip to content

Commit 4f5f598

Browse files
author
Spike Brehm
authored
Merge pull request react-native-maps#567 from ryankask/fit-to-elements-fix
Don't fit to elements if no positions added
2 parents e4b1d9b + fcb88c6 commit 4f5f598

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
@@ -462,20 +462,27 @@ public void animateToCoordinate(LatLng coordinate, int duration) {
462462

463463
public void fitToElements(boolean animated) {
464464
LatLngBounds.Builder builder = new LatLngBounds.Builder();
465+
466+
boolean addedPosition = false;
467+
465468
for (AirMapFeature feature : features) {
466469
if (feature instanceof AirMapMarker) {
467470
Marker marker = (Marker) feature.getFeature();
468471
builder.include(marker.getPosition());
472+
addedPosition = true;
469473
}
470474
// TODO(lmr): may want to include shapes / etc.
471475
}
472-
LatLngBounds bounds = builder.build();
473-
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 50);
474-
if (animated) {
475-
startMonitoringRegion();
476-
map.animateCamera(cu);
477-
} else {
478-
map.moveCamera(cu);
476+
477+
if (addedPosition) {
478+
LatLngBounds bounds = builder.build();
479+
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 50);
480+
if (animated) {
481+
startMonitoringRegion();
482+
map.animateCamera(cu);
483+
} else {
484+
map.moveCamera(cu);
485+
}
479486
}
480487
}
481488

0 commit comments

Comments
 (0)