I am trying to prevent the user from moving outside a certain area in a google map. However there does not seem to be an easy way to do this. First time asking here so have mercy.
I have tried the below in an effort to poll as the user scrolls, but the problem is that OnCameraChange doesn't fire often enough, so it works jerkily and inaccurately. I know there must be some way to do this as it seems like a simple and essential feature.
private static final LatLng NEBOUND = new LatLng(47.670606, -117.393344);
private static final LatLng SWBOUND = new LatLng(47.661283, -117.411052);
private static final LatLngBounds MAPBOUNDARY = new LatLngBounds(SWBOUND, NEBOUND);
private LatLng lastCenter = new LatLng(47.667454, -117.402309);
private final OnCameraChangeListener mOnCameraChangeListener =
new OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition cameraPosition) {
LatLngBounds visibleBounds = guMap.getProjection().getVisibleRegion().latLngBounds;
if(!MAPBOUNDARY.contains(visibleBounds.northeast) || !MAPBOUNDARY.contains(visibleBounds.southwest)){
guMap.moveCamera(CameraUpdateFactory.newLatLng(lastCenter));
}
else
lastCenter = guMap.getCameraPosition().target;
centerLoc.setText(lastCenter.toString());
}
};