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检索我之前存储在应用程序中的地图位置“它显示以下错误:
“无法将'_ NSCFString'类型的值(0x1604da4)转换为'NSNumber'(0x971800)”
答案 0 :(得分:1)
使用以下代码存储纬度和经度
#include <iostream>
void CompressString (std::string str)
{
//count will keep track of the number of occurences of any given character
unsigned int count = 1;
//new string to store the values from the original string
std::string str2 = "";
//store the first letter of the string initially
char ch = str[0];
//run a loop from the second character of the string since first character if stored in "ch"
for (unsigned int i = 1; i < str.length(); i++)
{
if (str[i] == ch)
count++;
else
{
str2 = str2 + ch + std::to_string (count);
ch = str[i];
count = 1;
}
}
//for cases like aabbb
str2 = str2 + ch + std::to_string (count);
//check if after compression, the length of the string reduces or not
if (str.length() > str2.length())
std::cout << str2 << std::endl;
else
std::cout << str << std::endl;
}
int main ()
{
std::cout << "Enter a string to compress: ";
std::string str;
getline (std::cin, str);
std::cout << "Compressed string is: ";
CompressString (str);
return 0;
}
用于检索
[[NSUserDefaults standardUserDefaults] setDouble:latitude forKey:klat]
[[NSUserDefaults standardUserDefaults] setDouble:longitude forKey:klong]