2017-04-24 20 views
0

내지도보기에는 대상 벽화에 대한 사용자 위치와 주석이 모두 표시되지만 확대/축소는 꺼져 있습니다. 현재 위치와 대상 주석이 얼마나 멀리 떨어져 있고 중심에 위치하는지에 따라 현재 주석과 대상 주석에 맞게 확장 할 수 있습니까?사용자 위치 및 주석지도보기에 맞게 확대/축소


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

답변

0

당신은 '(: 애니메이션 MKCoordinateRegion : BOOL _ 지역) FUNC의 setRegion'를 사용할 수는 (지금까지 거리) 확대 방법이다. MKCoordinateRegion에는 가운데가 있으며 영역의 범위도 정의됩니다. 여기서 중심은 사용자 위치와 대상에서 같은 거리에있는 지점 일 수 있습니다. 그에 따라 스팬을 결정할 수 있습니다. 이 longSpan = muralLocation.userLocation.coordinate.longitude하자 coordinates.latitude - -

+0

이 latSpan = muralLocation.userLocation.coordinate.latitude 할 VAR지도를 coordinates.longitude = MKCoordinateRegion() 하자 스팬 = MKCoordinateSpanMake (latSpan, longSpan) map.center = muralLocation.userLocation.coordinate map.span = span –

+0

나는 이것을했지만지도 줌이 흔들리지 않았다 ... 어떤 도움이 필요합니까? –