2017-02-07 4 views
0

Ich verwende diesen Code für setzen aktuellen Standort in der Mitte auf der KarteZoom auf Benutzerstandort hier Karte in 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) 

Aber ich habe Fehler unerwartet null gefunden, während ein optionaler Wert auszupacken. mir bitte sagen, wie bekomme ich aktuelle Position auf Mitte

+0

currentGeoPosition = NMAPositioningManager.sharedPositioningManager() lassen current diese Linie Problem schafft. –

+0

Ja, diese Linie schafft ein Problem, also wie man es überwinden kann. – Ranjan

+0

Es gibt keine Nil zurück, während die aktuelle Position von NMAPositioningManager.sharedPositioningManager abgerufen wird. ist das in Ordnung, wenn Sie Ihren aktuellen Standort von Corelocation nehmen? –

Antwort

0

können Sie aktuelle Position erhalten, indem diese (lat, long):

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) 
} 
+0

Danke, dass es funktioniert. – Ranjan

+0

Sie sind herzlich willkommen @Ranjan –

Verwandte Themen