Skip to content

Instantly share code, notes, and snippets.

@charvoa
Last active December 5, 2018 15:26
Show Gist options
  • Save charvoa/aa4adb6de4187196382e778c3c3fec75 to your computer and use it in GitHub Desktop.
Save charvoa/aa4adb6de4187196382e778c3c3fec75 to your computer and use it in GitHub Desktop.
func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
let center = mapView.region.center
let latitudeDelta = mapView.region.span.latitudeDelta
let topPin = CLLocation(latitude: center.latitude - (latitudeDelta / 2),
longitude: center.longitude)
let bottomPin = CLLocation(latitude: center.latitude + (latitudeDelta / 2),
longitude: center.longitude)
let centerLocation = CLLocation(latitude: center.latitude,
longitude: center.longitude)
let distance = max(topPin.distance(from: centerLocation),
bottomPin.distance(from: centerLocation))
reloadData()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment