我使用此代码在 map 中心设置当前位置
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
mapView.positionIndicator.visible = true
mapView.positionIndicator.accuracyIndicatorColor = UIColor.greenColor()
mapView.positionIndicator.accuracyIndicatorVisible = true
mapView.zoomLevel = 13.2
let currentGeoPosition=NMAPositioningManager.sharedPositioningManager().currentPosition
mapView.setGeoCenter(currentGeoPosition.coordinates, withAnimation: .Bow)
但是我在解包可选值时意外发现 nil 错误。 请告诉我如何获取中心的当前位置
最佳答案
您可以通过以下方式获取当前位置(纬度,经度):
import CoreLocation
let locationManger = CLLocationManager()
locationManger.delegate = self
locationManger.desiredAccuracy = kCLLocationAccuracyBest
locationManger.requestWhenInUseAuthorization()
locationManger.startUpdatingLocation()
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print (locations)
let locValue:CLLocationCoordinate2D = manager.location!.coordinate
let lat = String(locValue.latitude)
let lang = String(locValue.longitude)
}
关于ios - 快速放大此处 map 中的用户位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42081728/