我不知道如何让地图从viewDidLoad放大用户位置。我试着设置一个区域,但没有成功。这是我的密码,有什么建议吗?
@IBOutlet弱变量mapView: MKMapView!var MapViewLocationManager:CLLocationManager!= CLLocationManager() var currentLocation: PFGeoPoint!= PFGeoPoint()
override func viewDidLoad() {
super.viewDidLoad()
self.mapView.showsUserLocation = true
mapView.delegate = self
MapViewLocationManager.delegate = self
mapView.setUserTrackingMode(MKUserTrackingMode.Follow, animated: true)
}我已经查找了这个问题的答案,但还没有在Swift中找到答案,也没有找到真正有效的答案。谢谢!!
发布于 2015-06-25 03:24:20
我会尝试这样的方法:
let latitude:CLLocationDegrees = //insert latitutde
let longitude:CLLocationDegrees = //insert longitude
let latDelta:CLLocationDegrees = 0.05
let lonDelta:CLLocationDegrees = 0.05
let span = MKCoordinateSpanMake(latDelta, lonDelta)
let location = CLLocationCoordinate2DMake(latitude, longitude)
let region = MKCoordinateRegionMake(location, span)
mapView.setRegion(region, animated: false)我看到你说你试着设置一个区域。也许试着这样做。
发布于 2016-12-26 19:24:18
在大多数应用程序中,都会实现“当前位置”按钮。一个简单的方法是这样做:
@IBAction func myLocationButtonTapped(_ sender: Any) {
mapView.showsUserLocation = true
mapView.setUserTrackingMode(.follow, animated: true)
}一旦用户调整或缩放地图,跟踪将停止。所以对我来说已经够好了。
发布于 2017-01-04 11:38:40
你得试试这个。它会放大地图。
let span = MKCoordinateSpanMake(0.050, 0.050)
let region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 23.0225, longitude: 72.5714), span: span)
mapView.setRegion(region, animated: true)`https://stackoverflow.com/questions/31040667
复制相似问题