how can I center my map on the annotation view only when it is close to the edge of the screen?

落花浮王杯 提交于 2019-12-04 20:30:41

I would not compare the location of your annotation to all four edges, but check the distance from the center location.

let distance = center.distanceFromLocation(annotationLocation)

If this distance is bigger than a certain radius, the annotation is close to one of the edges.

if distance > radius {
    //center annotation
}

The radius can be calculated from the region span.

let radius = min(region.span.longitudeDelta, region.span.latitudeDelta) * 0.3
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!