Skip to content

Commit

Permalink
Merge pull request getodk#5393 from seadowg/unsupported-zoom
Browse files Browse the repository at this point in the history
Zoom out as far as possible when Google Maps can't handle lat/lng bounds for zoom to fit
  • Loading branch information
seadowg committed Jan 25, 2023
1 parent 426cbd2 commit 984160c
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
import org.odk.collect.maps.MapFragment;
import org.odk.collect.maps.MapFragmentDelegate;
import org.odk.collect.maps.MapPoint;
import org.odk.collect.maps.markers.MarkerDescription;
import org.odk.collect.maps.markers.MarkerIconDescription;
import org.odk.collect.maps.layers.MapFragmentReferenceLayerUtils;
import org.odk.collect.maps.layers.ReferenceLayerRepository;
import org.odk.collect.maps.markers.MarkerDescription;
import org.odk.collect.maps.markers.MarkerIconDescription;
import org.odk.collect.settings.SettingsProvider;

import java.io.File;
Expand Down Expand Up @@ -257,7 +257,12 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
} else if (count > 1) {
final LatLngBounds bounds = expandBounds(builder.build(), 1 / scaleFactor);
new Handler().postDelayed(() -> {
moveOrAnimateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0), animate);
try {
moveOrAnimateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 0), animate);
} catch (IllegalArgumentException e) { // https://github.com/getodk/collect/issues/5379
LatLng boxCenter = bounds.getCenter();
zoomToPoint(new MapPoint(boxCenter.latitude, boxCenter.longitude), map.getMinZoomLevel(), false);
}
}, 100);
}
}
Expand Down

0 comments on commit 984160c

Please sign in to comment.