I\'m trying to add a custom image to an MKMapView as an MKOverlayView - I need to restrict users from being able to scroll outside the bounds of th
simple solution for use inside mapViewDidFinishLoadingMap:
func mapViewDidFinishLoadingMap(_ mapView: MKMapView) {
//center of USA, roughly. for example
let center = CLLocationCoordinate2D(latitude: 38.573936, longitude: -92.603760)
let latMeters = CLLocationDistance(10_000_000.00) //left and right pan
let longMeters = CLLocationDistance(5_000_000.00) //up and down pan
let coordinateRegion = MKCoordinateRegion(
center: center,
latitudinalMeters: latMeters,
longitudinalMeters: longMeters)
let cameraBoundary = MKMapView.CameraBoundary(coordinateRegion: coordinateRegion)
mapView.setCameraBoundary(cameraBoundary, animated: true)
}