更新时间:2023-02-06 23:26:57
我为步行活动添加了另一个条件,并且仅将精度限制在0-60米之间.并且工作得很好.感谢上面的Allessandro和Skladek的反馈.
I have added another condition for walking activity and limited only accuracy between 0-60 meters. and work perfectly fine. Thanks Allessandro and Skladek feedback above.
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
iNEAT_o_GamesAppDelegate *appDelegate = (iNEAT_o_GamesAppDelegate *)[[UIApplication sharedApplication] delegate];
CoordinateModel *coord = [[CoordinateModel alloc] init];
ActivityType currentActivityType = [DataManager sharedInstance].activityType;
for(int i=0;i<locations.count;i++){
CLLocation * newLocation = [locations objectAtIndex:i];
CLLocationCoordinate2D theLocation = newLocation.coordinate;
CLLocationAccuracy theAccuracy = newLocation.horizontalAccuracy;
NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
if (locationAge > 30.0)
continue;
//Select only valid location and also location with good accuracy
if(newLocation!=nil&&theAccuracy>0
&&theAccuracy<2000
&&(!(theLocation.latitude==0.0&&theLocation.longitude==0.0))){
coord.latitude = theLocation.latitude;
coord.longitude = theLocation.longitude;
if (currentActivityType == 0 && theAccuracy<60) {
// walking
[appDelegate.walkingCoordinates addObject:coord];
}
else if(currentActivityType == 1) {
[appDelegate.bikingCoordinates addObject:coord];
}
else if(currentActivityType == 2) {
// driving
[appDelegate.drivingCoordinates addObject:coord];
}
}
}
}