Save longitude and latitude in SQLite database
I am creating a map application in Objective-C, for iPhone. I know how to get the current location of the user, and the destination location. As a user travels, his coordinates (latitude and longitude) change.
How can I save the latitude and longitude of the user in an 开发者_运维问答SQLite database every five minutes as the user travels?
I doubt you really always want to store the coordinates every 5 minutes. When using Core Location you subscribe to events that the user has changed position (and you can set accuracy) so you can get notified when the user has moved at all, and then choose to store the coordinates in a database. If you don't get events, then you know the user hasn't changed position.
You can use a timer and set time interval to 300, as shown below
[NSTimer scheduledTimerWithTimeInterval:300 target:self selector:@selector(*savetodatabase*) userInfo:nil repeats:YES];
Make one function which is called every 5 mins and save it to database.
NOTE: Here 300 is in seconds
You can call a method by using NSTimer which will add lat and long do database.
[NSTimer scheduledTimerWithTimeInterval:<(NSTimeInterval)ti> target:<(id)aTarget> selector:<(SEL)aSelector> userInfo:<(id)userInfo> repeats:<(BOOL)yesOrNo>]
you can use timer that after every 5 min a call to SAVEDATABASEFILE method
精彩评论