我在 Xcode 中创建了一个字符串,如下所示:
@property (nonatomic, retain) NSString *lati;
我也合成了。。。
现在在我的 viewLoad 中,我通过这个函数得到了我的纬度:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
int degrees = newLocation.coordinate.latitude;
double decimal = fabs(newLocation.coordinate.latitude - degrees);
int minutes = decimal * 60;
double seconds = decimal * 3600 - minutes * 60;
lati = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
//latLabel.text = lat;
degrees = newLocation.coordinate.longitude;
decimal = fabs(newLocation.coordinate.longitude - degrees);
minutes = decimal * 60;
seconds = decimal * 3600 - minutes * 60;
longi = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
}
后来我想将一些字符串保存到我的 slite3 数据库中,但我得到了一个 Bad_Access,因为我的 Lati 字符串没有正确设置,但我不知道为什么......这是我的 SaveToDB 方法:
if (sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK) {
NSString *insertSQL = [NSString stringWithFormat:@"INSERT INTO DATEN(download, upload, ping, comment, date, network, latitude, longitude) VALUES (\"%@\", \"%@\", \"%@\",\"%@\", \"%@\",\"%@\", \"%@\",\"%@\")",topDownloadLabel.text, topUploadLabel.text, pingLabel.text, Comment, string, WlanOrUmts, lati, longi];
我得到了 Bad_Access。