MKMapView中心并放大 [英] MKMapView center and zoom in

查看:225
本文介绍了MKMapView中心并放大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个项目上使用MKMapView,并希望将地图中心放在一个坐标上并放大.就像Google地图一样:

I am using MKMapView on a project and would like to center the map on a coordinate and zoom in. Just like Google maps has:

GMSCameraPosition.camera(withLatitude: -33.8683,
                                  longitude: 151.2086,
                                  zoom: 6)

有任何Mapkit方法吗?

Is there any Mapkit method for this?

推荐答案

以下是我使用MKCoordinateRegion将地图集中在预先定义的CLLocation上的一种方法.

Here is a method I use to center your map on a pre-defined CLLocation using MKCoordinateRegion.

func centerMapOnLocation(_ location: CLLocation, mapView: MKMapView) {
    let regionRadius: CLLocationDistance = 1000
    let coordinateRegion = MKCoordinateRegionMakeWithDistance(location.coordinate,
        regionRadius * 2.0, regionRadius * 2.0)
    mapView.setRegion(coordinateRegion, animated: true)
}

这篇关于MKMapView中心并放大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆