如何删除错误的GPS坐标 [英] How to Remove Bad GPS Coordinate

查看:469
本文介绍了如何删除错误的GPS坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如下图所示,当我跟踪用户活动(步行,骑自行车或驾驶)时,GPS坐标突然跳跃.

As shown in the image below, there is a sudden jump in GPS coordinate while I keep track of user activity (walking, biking or driving).

即使我已经尝试了多种解决方法,我也不知道如何解决此问题,但是作为参考,我也在下面发布了我的代码.

I do not know how to fix this problem even though I have already attempted multiple ways to solve, but as a reference I also posted my code below.

在此图像截图中,我停了车,走到校园,来到我的办公室,但这显示我去了Harvest Ln,那是不对的.

In this image screenshot, I parked my car and walked to campus and came to my office, but it shows me that I went to Harvest Ln which is not right.

   -(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的反馈.

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

这篇关于如何删除错误的GPS坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆