在swift中放大此处地图中的用户位置

时间:2017-02-07 04:28:01

标签: ios swift

我正在使用此代码在地图中心设置当前位置

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错误。 请告诉我如何获得中心的当前位置

1 个答案:

答案 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)
 }