Skip to content

Instantly share code, notes, and snippets.

@dgyesbreghs
Created June 29, 2017 16:28
Show Gist options
  • Save dgyesbreghs/0a8802acb78a3cb44beaaf837a520b83 to your computer and use it in GitHub Desktop.
Save dgyesbreghs/0a8802acb78a3cb44beaaf837a520b83 to your computer and use it in GitHub Desktop.
//
// MKMapRect+Conversion.swift
//
// Created by Dylan Gyesbreghs on 29/06/2017.
// Copyright © 2017 Dylan Gyesbreghs. All rights reserved.
//
import MapKit
extension MKMapRect {
var northEastCoordinate: CLLocationCoordinate2D {
return coordinateFromMapRectanglePoint(MKMapRectGetMaxX(self), origin.y)
}
var northWestCoordinate: CLLocationCoordinate2D {
return coordinateFromMapRectanglePoint(MKMapRectGetMinX(self), origin.y)
}
var southEastCoordinate: CLLocationCoordinate2D {
return coordinateFromMapRectanglePoint(MKMapRectGetMaxX(self), MKMapRectGetMaxY(self))
}
var southWestCoordinate: CLLocationCoordinate2D {
return coordinateFromMapRectanglePoint(origin.x, MKMapRectGetMaxY(self))
}
fileprivate func coordinateFromMapRectanglePoint(_ x: Double, _ y: Double) -> CLLocationCoordinate2D { //swiftlint:disable:this identifier_name line_length
let mapPoint = MKMapPoint(x: x, y: y)
return MKCoordinateForMapPoint(mapPoint)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment