Skip to content

Instantly share code, notes, and snippets.

Dion Crannitch dionc

View GitHub Profile
dionc / MapKitExtensions.swift
Last active May 11, 2020
Create an MKCoordinateRegion from an array of coordinates. Safely handles coordinates that cross the 180th meridian.
View MapKitExtensions.swift
import MapKit
extension MKCoordinateRegion {
init?(coordinates: [CLLocationCoordinate2D]) {
// first create a region centered around the prime meridian
let primeRegion = MKCoordinateRegion.region(for: coordinates, transform: { $0 }, inverseTransform: { $0 })
// next create a region centered around the 180th meridian
You can’t perform that action at this time.