无法使用 swift ios 在 mapView 中检索纬度和经度位置

Unable to retrieve lat and long locations in mapView using swift ios

let latitude = NSUserDefaults .standardUserDefaults().valueForKey(klat) as! Double

 let longitude = NSUserDefaults .standardUserDefaults().valueForKey(klong) as! Double


let location:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)

//Second Location lat and long
let latitudeSec:CLLocationDegrees = 11.0100
let longitudeSec:CLLocationDegrees = 77.3620

let locationSec:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitudeSec, longitudeSec)

let span:MKCoordinateSpan = MKCoordinateSpanMake(1, 1)

let region:MKCoordinateRegion = MKCoordinateRegionMake(location, span)

mapView.setRegion(region, animated: true)


let myAn1 = MyAnnotation(title: "Office", coordinate: location,subtitle: "MyOffice");

我无法在此处检索地图位置,我之前使用关键字 "klat and "klong 中的 NSUserDefaults 存储在应用程序中”它显示以下错误:

"Could not cast value of type '__NSCFString' (0x1604da4) to 'NSNumber' (0x971800)"

使用以下代码存储纬度和经度

[[NSUserDefaults standardUserDefaults] setDouble:latitude forKey:klat]
[[NSUserDefaults standardUserDefaults] setDouble:longitude forKey:klong]

并用于检索

let latitude = NSUserDefaults.standardUserDefaults().doubleForKey(klat)
let latitude = NSUserDefaults.standardUserDefaults().doubleForKey(klong)