Is there a way to restrict MKMapView Zoomlevel in iOS6 (Is there a way to restrict MKMapView Zoomlevel in iOS6)


문제 설명

Is there a way to restrict MKMapView Zoomlevel in iOS6 (Is there a way to restrict MKMapView Zoomlevel in iOS6)

In one of my iPad apps, I use MKMapView to show regions and I have a weird issue. I use setRegion: animated: method to set a particular region from a noOf points. When I zoom from that particular point in the map, the map shows grids with no image of the place/location. Does anyone has the same issue before? Can someone provide a solution for how to handle this zoom level issue?

Attaching the image for more reference

Initially, I call the setRegion: method of mapview with a 2d co‑ordinate and its span as 0.0014f for both latitude and longitude delta values. So I get the following image.

After that if I try to zoom in the mapview again, it goes to a situation like the following

My concern is, whether there is a way to restrict the zoom in to avoid the black layer display/how can I restrict the zoom in once mapview reaches its best possible zoomed cells.


참조 솔루션

방법 1:

when you zoom in CLOSE the mapview wants to show the most detailed tiles and nothin else. For certain areas (gov, military or places where there is nothing) there are no tiles and it runs into that!

the problem is that you dont know beforehand where there are or aren't any tiles available.

what I could imagine: when you zoom.  regionWillChange: is called and then willStartLoading: should be called and then mapViewDidFailLoadingMap:withError in the case of no tiles

(im guessing here)

방법 2:

In Swift just you should use from following code for define minimum and maximum zoom limitation

let MIN_ZOOM_LEVEL = 16.5
let MAX_ZOOM_LEVEL = 18.0

extension UIViewController: MKMapViewDelegate {
    func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
            let coordinate = CLLocationCoordinate2DMake(mapView.region.center.latitude, mapView.region.center.longitude)
            let zoomLevel = getZoomLevel()

            if MIN_ZOOM_LEVEL > zoomLevel || MAX_ZOOM_LEVEL < zoomLevel {
                let region = MKCoordinateRegionMake(coordinate, self.latestSpan)
                mapView.setRegion(region, animated:true)
            } else {
                self.latestSpan = MKCoordinateSpanMake(0, 360 / pow(2, Double(zoomLevel‑1)) * Double(mapView.frame.size.width) / 256)
            }
    }
}


func getZoomLevel() ‑> Double {
        var angleCamera = mapView.camera.heading
        if angleCamera > 270 {
            angleCamera = 360 ‑ angleCamera
        } else if angleCamera > 90 {
            angleCamera = fabs(angleCamera ‑ 180)
        }
        let angleRad = M_PI * angleCamera / 180
        let width = Double(mapView.frame.size.width)
        let height = Double(mapView.frame.size.height)
        let heightOffset : Double = 20
        let spanStraight = width * mapView.region.span.longitudeDelta / (width * cos(angleRad) + (height ‑ heightOffset) * sin(angleRad))
        return log2(360 * ((width / 256) / spanStraight)) + 1
}

(by Sagar S. KadookkunnanDaij‑DjanSaeed)

참조 문서

  1. Is there a way to restrict MKMapView Zoomlevel in iOS6 (CC BY‑SA 3.0/4.0)

#mkmapview #ios6 #iOS #ipad






관련 질문

지도 보기에서 현재 위치 확대 (Zoom on Current Location in Map View)

Is there a way to restrict MKMapView Zoomlevel in iOS6 (Is there a way to restrict MKMapView Zoomlevel in iOS6)

MKMapView가 약 180도 스크롤되지 않습니다. (MKMapView does not scroll around 180 degrees)

mapView에서 길찾기 버튼을 만드는 방법은 무엇입니까? (How to create get direction button in mapView?)

MKMapview를 사용하는 동안 MB의 메모리 사용량이 발생하고 ARC를 사용하는 동안 View가 사라질 때 메모리가 해제되지 않습니다. (While using MKMapview causing MBs of memory usage and using ARC it not releasing memory when View Disappears)

UITextFieldShouldChange가 두 번 호출됨 (UITextFieldShouldChange being called twice)

Mapview Xcode에서 위치 업데이트 (Update Location in Mapview Xcode)

MKMapView 폐색이 주석을 제거합니까? (Does MKMapView occlusion cull it's annotations?)

값이 없는 경우 HTML5 로컬 저장소 개체는 무엇을 반환합니까? (What does the HTML5 Local Storage object return if there is no value?)

MKMapView에서 사용자 위치를 찾는 데 문제가 있음 (Problems Trying to Find User Location in MKMapView)

MKMapView에 주석을 추가할 때 백그라운드에서 앱 충돌 (Crashes app in background when adding annotation on MKMapView)

모든 프로젝트 Swift 5에서 1개의 MapView를 공유하는 방법 (How to Share 1 MapView in all Project Swift 5)







코멘트