gpt4 book ai didi

ios - 如何删除错误的 GPS 坐标

转载 作者:行者123 更新时间:2023-11-29 12:45:08 24 4
gpt4 key购买 nike

如下图所示,当我跟踪用户事件(步行、骑自行车或开车)时,GPS 坐标突然跳跃。

虽然我已经尝试了多种方法来解决这个问题,但我不知道如何解决这个问题,但作为引用,我还在下面发布了我的代码。

在这张图片截图中,我把车停好,步行到校园,然后来到我的办公室,但它显示我去了 Harvest Ln,这是不对的。 enter image description here

   -(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) {
// walking
[appDelegate.walkingCoordinates addObject:coord];
}
else if(currentActivityType == 1) {
[appDelegate.bikingCoordinates addObject:coord];
}
else if(currentActivityType == 2) {
// driving
[appDelegate.drivingCoordinates addObject:coord];
}
}
}
}

最佳答案

我为步行事件添加了另一个条件,并且仅将精度限制在 0-60 米之间。并且工作得很好。感谢上面的 Allessandro 和 Skladek 反馈。

 -(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];
}
}
}
}

关于ios - 如何删除错误的 GPS 坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23833758/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com