Eric
Eric

Reputation: 141

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

I am using MKTileOverlay to overlay an old map on top of Apple maps.

The overlay is tiled and covers a region of about 10 square miles.

All seems to work fine in that the overlay renders correctly.

However, it appears the renderer is trying to load overlay tiles for the whole region in view, even when the tile image files do not exist because they are outside the overlay map area.

This results in logging of a stream of error messages.

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

I have tried subclassing MKTileOverlay and trapping the cases where the URL is not found but without success.

Does anyone know how to solve this?

Upvotes: 0

Views: 365

Answers (1)

Eric
Eric

Reputation: 141

Thanks to user: junkpile on Apple Developer forum, need to subclass MKTileOverlay to restrict boundingMapRect to required size.

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)); 
            }
        }
}

Upvotes: 0

Related Questions