感谢用户:Apple 开发者论坛上的垃圾堆,需要继承 MKTileOverlay以将boundingMapRect限制为所需的大小。
import MapKit
class CustomTileOverlay : MKTileOverlay {
override var boundingMapRect: MKMapRect {
get {
//North-East Corner of overlay region
let lat1 = 53.46075
let long1 = -1.92618
//South-West Corner of overlay region
let lat2 = 53.43018
let long2 = -1.992885
//Convert to Coordinates
let coord1 = CLLocationCoordinate2DMake(lat1,long1)
let coord2 = CLLocationCoordinate2DMake(lat2,long2)
//Convert to map points
let p1 = MKMapPointForCoordinate (coord1);
let p2 = MKMapPointForCoordinate (coord2);
//Return the MKMapRect
return MKMapRectMake(fmin(p1.x,p2.x), fmin(p1.y,p2.y), fabs(p1.x-p2.x), fabs(p1.y-p2.y));
}
}
}