我在一个项目上使用MKMapView,并希望将地图置于坐标上并放大.就像谷歌地图有:
GMSCameraPosition.camera(withLatitude: -33.8683, longitude: 151.2086, zoom: 6)
有没有Mapkit方法呢?
您将创建一个MKCoordinateRegion对象并将其设置为MKMapView对象上的区域.
MKCoordinateRegion mapRegion; CLLocationCoordinate2D coordinate; coordinate.latitude = 0; coordinate.longitude = 0; mapRegion.center = coordinate; mapRegion.span.latitudeDelta = 0.2; mapRegion.span.longitudeDelta = 0.2; [mapView setRegion:mapRegion animated: YES];
这是我用于将地图置于预定义CLLocation
使用中心的方法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) }