0
我的地圖視圖顯示目標壁畫的用戶位置和註釋,但縮放關閉。我如何根據它們之間的距離和居中距離來使其適合當前位置和目的地註釋?縮放以適合用戶位置和註記地圖視圖swift
func mapPoints(){
let annotations = MKPointAnnotation()
annotations.title = muralModel.muralName!
muralModel.getMainArtistModel(completion: { (anArtistModel) in
annotations.subtitle = " \(anArtistModel!.firstName!) \(anArtistModel!.lastName!)"
})
annotations.coordinate = coordinates
muralLocation.addAnnotation(annotations)
self.muralLocation.showsUserLocation = true
var zoomRect: MKMapRect = MKMapRectNull
let mapEdgePadding = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)
//convert CLLocationCoordinate2D to MKMapPointForCoordinate so you don't end up in Bering Sea
let userPoint = MKMapPointForCoordinate(muralLocation.userLocation.coordinate)
let destinationPoint = MKMapPointForCoordinate(coordinates)
let userPointRect = MKMapRectMake(userPoint.x, userPoint.y, 0.1, 0.1)
let destinationPointRect = MKMapRectMake(destinationPoint.x, destinationPoint.y, 0.1, 0.1)
zoomRect = userPointRect
zoomRect = MKMapRectUnion(zoomRect, destinationPointRect)
muralLocation.setVisibleMapRect(zoomRect, edgePadding: mapEdgePadding, animated: true)
}
讓latSpan = muralLocation.userLocation.coordinate.latitude - coordinates.latitude 讓大跨度= muralLocation.userLocation.coordinate.longitude - coordinates.longitude 變種地圖= MKCoordinateRegion() 設跨度= MKCoordinateSpanMake(latSpan, longSpan) map.center = muralLocation.userLocation.coordinate map.span = span –
我這樣做了,但是地圖縮放沒有預算......有幫助嗎? –