MKTileOverlay - "The requested URL was not found on this server."



我正在使用MKTileOverlay将旧地图覆盖在苹果地图上。

覆盖层是平铺的,覆盖面积约为10平方英里。

所有的工作似乎都很好,因为覆盖渲染正确。

但是,渲染器似乎正在尝试加载视图中整个区域的覆盖平铺,即使平铺图像文件不存在,因为它们在覆盖贴图区域之外。

这将导致错误消息流的日志记录。

Error Domain=NSURLErrorDomain Code=-1100 
"The requested URL was not found on this server." 

我尝试过对MKTileOverlay进行子类化,并捕获了找不到URL但没有成功的情况。

有人知道怎么解决这个问题吗?

感谢用户:苹果开发者论坛上的垃圾堆,需要子类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)); 
            }
        }
}

相关内容

最新更新