【发布时间】:2018-04-23 04:21:22
【问题描述】:
我正在尝试使用坐标缩放到某个位置。 我怎样才能做到这一点?
【问题讨论】:
-
你说的是地图视图吗?您是说您有一个纬度/经度地图坐标,并且您想将地图缩放到该点吗?你需要更清楚、更具体。
我正在尝试使用坐标缩放到某个位置。 我怎样才能做到这一点?
【问题讨论】:
import UIKit
import MapKit
class HomeViewController: UIViewController, MKMapViewDelegate {
@IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
mapView.showsUserLocation = true
if let userLocation = mapView.userLocation.location {
//let frontedUserLocation = CLLocationCoordinate2DMake(37.7857, -122.4021)
mapView.centerCoordinate = userLocation.coordinate
//mapView.centerCoordinate = frontedUserLocation
//let region = MKCoordinateRegionMakeWithDistance(frontedUserLocation, 1855, 1855)
let region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 9484.1, 9484.1)
mapView.setRegion(region, animated: true)
}
mapView.delegate = self
}
【讨论】: