我正在使用此代码在地图中心设置当前位置
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)
但是在解开Optional值时我意外地发现了nil错误。 请告诉我如何获得中心的当前位置
答案 0 :(得分:0)
你可以通过这个得到当前位置(纬度,长度):
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)
}