我假设您正在使用 CLLocationManagerDelegate?
因此,当找到一个新位置时,它会发送到此方法:
– (void)locationManager:didUpdateToLocation:fromLocation:
从那里您可以调用将值写入数据库并将您的值作为参数传递的方法。例如:
– (void)locationManager:(CLLocationManager *)locationManager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)newLocation {
NSString *latitude = [NSString stringWithFormat:@"%f", newLocation.coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:@"%f", newLocation.coordinate.longitude];
NSString *stringFromDate = [formatter stringFromDate: newLocation.timestamp];
[self myFuntionThatWritesToDatabaseWithLatitude:latitude longitude:longitude date:stringFromDate];
}
- (void)myFuntionThatWritesToDatabaseWithLatitude:(NSString *)latitude longitude:(NSString *)longitude date:(NSString *)stringFromDate {
// write to Database
}