放大用户位置 - Swift
Zoom in on User Location- Swift
我不知道如何让地图从 viewDidLoad 放大用户位置。我尝试设置一个区域,但没有用。这是我的代码,有什么提示吗?
@IBOutlet 弱变量 mapView:MKMapView!
变量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 中找到答案或实际有效的答案。谢谢!!
我会尝试这样的事情:
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)
我看到你说你试过设置区域。也许尝试这样做。
在大多数应用程序中,实现了一个 'current location' 按钮。一个简单的方法是这样的:
@IBAction func myLocationButtonTapped(_ sender: Any) {
mapView.showsUserLocation = true
mapView.setUserTrackingMode(.follow, animated: true)
}
一旦用户平移或缩放地图,跟踪将停止。所以对我来说已经足够了。
你一定要试试这个。
它将缩放地图。
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)`
@IBOutlet weak var conscienceMap: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
conscienceMap.showsUserLocation = true
conscienceMap.setUserTrackingMode(MKUserTrackingMode.follow, animated: true)
}
我不知道如何让地图从 viewDidLoad 放大用户位置。我尝试设置一个区域,但没有用。这是我的代码,有什么提示吗?
@IBOutlet 弱变量 mapView:MKMapView! 变量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 中找到答案或实际有效的答案。谢谢!!
我会尝试这样的事情:
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)
我看到你说你试过设置区域。也许尝试这样做。
在大多数应用程序中,实现了一个 'current location' 按钮。一个简单的方法是这样的:
@IBAction func myLocationButtonTapped(_ sender: Any) {
mapView.showsUserLocation = true
mapView.setUserTrackingMode(.follow, animated: true)
}
一旦用户平移或缩放地图,跟踪将停止。所以对我来说已经足够了。
你一定要试试这个。 它将缩放地图。
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)`
@IBOutlet weak var conscienceMap: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
conscienceMap.showsUserLocation = true
conscienceMap.setUserTrackingMode(MKUserTrackingMode.follow, animated: true)
}