Ios MKMapView显示注释行为

Ios MKMapView显示注释行为,ios,mkmapview,Ios,Mkmapview,我的MKMapView不适合我添加到它的仅有两个注释 我想不出为什么会这样。我在另一个视图控制器中有另一个贴图,并且showAnnotations(\ u0:animated)工作正常。通过比较它们各自的代码,我找不到任何可能导致这种行为的东西 代码基本上是这样的: override func viewDidLoad() { super.viewDidLoad() annotationOrigin = aCoordinate annotationDest = bCoord

我的MKMapView不适合我添加到它的仅有两个注释

我想不出为什么会这样。我在另一个视图控制器中有另一个贴图,并且showAnnotations(\ u0:animated)工作正常。通过比较它们各自的代码,我找不到任何可能导致这种行为的东西

代码基本上是这样的:

override func viewDidLoad() {
    super.viewDidLoad()
    annotationOrigin = aCoordinate
    annotationDest = bCoordinate
    mapView.addAnnotations([annotationOrigin, annotationDest], animated: true)   
}

func mapViewDidFinishRenderingMap(_ mapView: MKMapView, fullyRendered: Bool) {
    mapView.showAnnotations([annotationOrigin, annotationDest], animated: true)
}
你可以试试这个

 func zoomToFitMapAnnotations(aMapView:MKMapView)
{
    if(aMapView.annotations.count == 0)
    {
          return
    }


    var topLeftCoord = CLLocationCoordinate2D.init(latitude: -90, longitude: 180)


    var bottomRightCoord = CLLocationCoordinate2D.init(latitude: 90, longitude: -180)


    for i in 0..<myMapView.annotations.count
    {
        let annotation = myMapView.annotations[i]

        topLeftCoord.longitude = fmin(topLeftCoord.longitude, annotation.coordinate.longitude);
        topLeftCoord.latitude = fmax(topLeftCoord.latitude, annotation.coordinate.latitude);

        bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, annotation.coordinate.longitude);
        bottomRightCoord.latitude = fmin(bottomRightCoord.latitude, annotation.coordinate.latitude);
    }


    let resd = CLLocationCoordinate2D.init(latitude: topLeftCoord.latitude - (topLeftCoord.latitude - bottomRightCoord.latitude) * 0.5, longitude: topLeftCoord.longitude + (bottomRightCoord.longitude - topLeftCoord.longitude) * 0.5)

    let span = MKCoordinateSpan.init(latitudeDelta: fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 1.3, longitudeDelta: fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 1.3)

    var region = MKCoordinateRegion.init(center: resd, span: span);



    region = aMapView.regionThatFits(region)

    aMapView.setRegion(region, animated: true)


}
func zoomtofitmanotations(aMapView:MKMapView)
{
if(aMapView.annotations.count==0)
{
返回
}
var topLeftCoord=cllocationcoordinae2d.init(纬度:-90,经度:180)
var bottomRightCoord=CLLocationCoordinate2D.init(纬度:90,经度:-180)
对于0..中的i,您可以试试这个

 func zoomToFitMapAnnotations(aMapView:MKMapView)
{
    if(aMapView.annotations.count == 0)
    {
          return
    }


    var topLeftCoord = CLLocationCoordinate2D.init(latitude: -90, longitude: 180)


    var bottomRightCoord = CLLocationCoordinate2D.init(latitude: 90, longitude: -180)


    for i in 0..<myMapView.annotations.count
    {
        let annotation = myMapView.annotations[i]

        topLeftCoord.longitude = fmin(topLeftCoord.longitude, annotation.coordinate.longitude);
        topLeftCoord.latitude = fmax(topLeftCoord.latitude, annotation.coordinate.latitude);

        bottomRightCoord.longitude = fmax(bottomRightCoord.longitude, annotation.coordinate.longitude);
        bottomRightCoord.latitude = fmin(bottomRightCoord.latitude, annotation.coordinate.latitude);
    }


    let resd = CLLocationCoordinate2D.init(latitude: topLeftCoord.latitude - (topLeftCoord.latitude - bottomRightCoord.latitude) * 0.5, longitude: topLeftCoord.longitude + (bottomRightCoord.longitude - topLeftCoord.longitude) * 0.5)

    let span = MKCoordinateSpan.init(latitudeDelta: fabs(topLeftCoord.latitude - bottomRightCoord.latitude) * 1.3, longitudeDelta: fabs(bottomRightCoord.longitude - topLeftCoord.longitude) * 1.3)

    var region = MKCoordinateRegion.init(center: resd, span: span);



    region = aMapView.regionThatFits(region)

    aMapView.setRegion(region, animated: true)


}
func zoomtofitmanotations(aMapView:MKMapView)
{
if(aMapView.annotations.count==0)
{
返回
}
var topLeftCoord=cllocationcoordinae2d.init(纬度:-90,经度:180)
var bottomRightCoord=CLLocationCoordinate2D.init(纬度:90,经度:-180)

因为我在0.没有运气:/相同的行为或没有运气:/相同的行为