嗨,我有以下代码,它可以在 1 英里范围内找到用户位置:
let initialLocation = CLLocation(latitude: 51.5001524, longitude: -0.1262362)
let regionRadius: CLLocationDistance = 1000
var locationManager: CLLocationManager!
override func viewDidLoad() {
super.viewDidLoad()
func centerMapOnLocation(location:CLLocation) {
let coordianteRegion = MKCoordinateRegionMakeWithDistance(location.coordinate,
regionRadius * 2.0, regionRadius * 2.0)
mapView.setRegion(coordianteRegion, animated: true)
}
// Do any additional setup after loading the view, typically from a nib.
centerMapOnLocation(initialLocation)
}
This is perfect as gets a decent radius for user location, however i want to know, how do you center map on user location?
我尝试了很多方法,但我似乎无法让 map 以用户位置为中心。
任何帮助将非常感激!
谢谢
最佳答案
MKMapView
有一个使用 userTrackingMode
属性的内置解决方案。
mapView.userTrackingMode = .Follow
关于ios - 如何在用户位置 IOS 9 SWIFT 上居中 map ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35705649/