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

标签 ios mapkit

如下图所示,当我跟踪用户事件(步行、骑自行车或开车)时,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/

相关文章:

iphone - 如何长按并抬起 MKAnnotationView

php - 使用不同语言的套接字对谜题进行编码

ios - Swift:AppDelegate 函数应用程序调用,但接下来会发生什么?

ios - OpenCV - 无法访问 Mat 中的所有像素

javascript - 连接失败 (1006) 消息 : TB. 套接字错误,连接超时 (1008)

ios - ios 8 中不支持的帧缓冲区格式

c# - C# 上的 Apple JWT 生成

ios - 将视频和音频 Assets 合并到Swift 3 iOS中后,在视频上添加水印

objective-c - iOS 和 Android 上两点之间的不同距离

ios - 如何设置MKMapView区域以缩放到userLocation的精度?