Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何过滤过近的坐标?_Ios_Objective C_Arrays_Coordinates - Fatal编程技术网

Ios 如何过滤过近的坐标?

Ios 如何过滤过近的坐标?,ios,objective-c,arrays,coordinates,Ios,Objective C,Arrays,Coordinates,我有一个这样的坐标数组(这只是一个示例): 我想过滤掉彼此太接近的坐标,以减小尺寸。我怎样才能做到这一点 我有个想法: 设置一个数字作为公差范围。 循环遍历数组中的每个坐标,检查它们之间的差异是否小于公差范围编号,如果小于,则删除其中一个坐标 这样行吗?如果是,如何在Objective-C中对其进行编码?NSArray*Array1=@[@“47.551090,18.961610”, NSArray *Array1 = @[@"47.551090,18.961610",

我有一个这样的坐标数组(这只是一个示例):

我想过滤掉彼此太接近的坐标,以减小尺寸。我怎样才能做到这一点

我有个想法:

设置一个数字作为公差范围。 循环遍历数组中的每个坐标,检查它们之间的差异是否小于公差范围编号,如果小于,则删除其中一个坐标

这样行吗?如果是,如何在Objective-C中对其进行编码?

NSArray*Array1=@[@“47.551090,18.961610”,
 NSArray *Array1 = @[@"47.551090,18.961610",
                    @"47.551010,18.961600",
                    @"47.550910,18.961600",
                    @"47.550830,18.961610",
                    @"47.550750,18.961640",
                    @"47.550690,18.961680",
                    @"47.549980,18.962870",
                    @"47.549170,18.964170",
                    @"47.548950,18.964500",
                    @"47.548840,18.964620",
                    @"47.548710,18.964690",
                    @"47.548470,18.964690",
                    @"47.548400,18.964690",
                    @"47.547990,18.964720"];

NSMutableArray *finalArr=[[NSMutableArray alloc] init];
CGFloat threshhold=0.0009;
for (NSString *str in Array1) {
    NSArray *temp=[str componentsSeparatedByString:@","];
    if(temp!=nil && [temp count]==2){
        BOOL isSame=NO;
        for(NSString *s in finalArr){
            NSArray *temp2=[s componentsSeparatedByString:@","];
            if(([[temp objectAtIndex:0] isEqualToString:[temp2 objectAtIndex:0]]) || ((((NSString*)[temp objectAtIndex:0])).floatValue-threshhold<=(((NSString*)[temp2 objectAtIndex:0])).floatValue && (((NSString*)[temp objectAtIndex:0])).floatValue+threshhold>=(((NSString*)[temp2 objectAtIndex:0])).floatValue)){
                isSame=YES;
                break;
            }

            if([[temp objectAtIndex:1] isEqualToString:[temp2 objectAtIndex:1]]){
                isSame=YES;
                break;
            }
        }

        if(isSame==NO){
            [finalArr addObject:str];
        }
    }
}
NSLog(@"%@",finalArr);
@"47.551010,18.961600", @"47.550910,18.961600", @"47.550830,18.961610", @"47.550750,18.961640", @"47.550690,18.961680", @"47.549980,18.962870", @"47.549170,18.964170", @"47.548950,18.964500", @"47.548840,18.964620", @"47.548710,18.964690", @"47.548470,18.964690", @"47.548400,18.964690", @"47.547990,18.964720"]; NSMutableArray*finalArr=[[NSMutableArray alloc]init]; CGFloat阈值=0.0009; for(数组1中的NSString*str){ NSArray*temp=[str组件由字符串分隔:@“,”]; 如果(温度!=nil&&[temp count]==2){ BOOL-isSame=否; 用于(最终中的NSString*s){ NSArray*temp2=[s组件由字符串分隔:@“,”]; if(([[temp objectAtIndex:0]isEqualToString:[temp2 objectAtIndex:0]])|((((NSString*)[temp objectAtIndex:0])).floatValue阈值=((NSString*)[temp2 objectAtIndex:0]).floatValue)){ IsName=是; 打破 } if([[temp objectAtIndex:1]isEqualToString:[temp2 objectAtIndex:1]])){ IsName=是; 打破 } } 如果(isSame==否){ [最终添加对象:str]; } } } NSLog(@“%@”,最终);
您可以根据需要设置阈值

NSArray*Array1=@[@“47.551090,18.961610”,
@"47.551010,18.961600",
@"47.550910,18.961600",
@"47.550830,18.961610",
@"47.550750,18.961640",
@"47.550690,18.961680",
@"47.549980,18.962870",
@"47.549170,18.964170",
@"47.548950,18.964500",
@"47.548840,18.964620",
@"47.548710,18.964690",
@"47.548470,18.964690",
@"47.548400,18.964690",
@"47.547990,18.964720"];
NSMutableArray*finalArr=[[NSMutableArray alloc]init];
CGFloat阈值=0.0009;
for(数组1中的NSString*str){
NSArray*temp=[str组件由字符串分隔:@“,”];
如果(温度!=nil&&[temp count]==2){
BOOL-isSame=否;
用于(最终中的NSString*s){
NSArray*temp2=[s组件由字符串分隔:@“,”];
if(([[temp objectAtIndex:0]isEqualToString:[temp2 objectAtIndex:0]])|((((NSString*)[temp objectAtIndex:0])).floatValue阈值=((NSString*)[temp2 objectAtIndex:0]).floatValue)){
IsName=是;
打破
}
if([[temp objectAtIndex:1]isEqualToString:[temp2 objectAtIndex:1]])){
IsName=是;
打破
}
}
如果(isSame==否){
[最终添加对象:str];
}
}
}
NSLog(@“%@”,最终);

您可以根据自己的要求设置阈值

您可以使用公差检查,但它不应该直接位于纬度和经度值之间,它应该是由纬度和经度表示的地理位置之间的距离公差(以米为单位)。纬度和经度的本质意味着你不能仅仅通过观察数值就知道两点之间的物理距离

为此,您可以从lat/long对中创建
CLLocation
的实例,然后使用
distanceFromLocation:
对其进行公差检查


您需要决定如何选择保留哪些位置和放弃哪些位置。有许多选项可供选择,其中许多需要多个回路以确保没有两个点彼此靠近。

您可以使用公差检查,但它不应直接位于纬度值和经度值之间,它应该是距离的公差,以米为单位,由纬度和经度表示的地理位置之间。纬度和经度的本质意味着你不能仅仅通过观察数值就知道两点之间的物理距离

为此,您可以从lat/long对中创建
CLLocation
的实例,然后使用
distanceFromLocation:
对其进行公差检查


您需要决定如何选择保留哪些位置和放弃哪些位置。有很多选择,其中许多需要多个循环,以确保没有两个点彼此靠近。

您的阵列不应该这样。若左栏是纬度,右栏是经度。我想应该是字典数组或者字典数组。或者应该有两个不同的纬度和经度数组在您的情况下应该输出什么?这是有原因的,不过感谢您的建议!如果所有内容都在一个数组中,那么如何比较?您将比较纬度和经度?您的数组不应该这样。若左栏是纬度,右栏是经度。我想应该是字典数组或者字典数组。或者应该有两个不同的纬度和经度数组在您的情况下应该输出什么?这是有原因的,不过感谢您的建议!如果所有内容都在一个数组中,那么如何比较?你会喜欢的
 NSArray *Array1 = @[@"47.551090,18.961610",
                    @"47.551010,18.961600",
                    @"47.550910,18.961600",
                    @"47.550830,18.961610",
                    @"47.550750,18.961640",
                    @"47.550690,18.961680",
                    @"47.549980,18.962870",
                    @"47.549170,18.964170",
                    @"47.548950,18.964500",
                    @"47.548840,18.964620",
                    @"47.548710,18.964690",
                    @"47.548470,18.964690",
                    @"47.548400,18.964690",
                    @"47.547990,18.964720"];

NSMutableArray *finalArr=[[NSMutableArray alloc] init];
CGFloat threshhold=0.0009;
for (NSString *str in Array1) {
    NSArray *temp=[str componentsSeparatedByString:@","];
    if(temp!=nil && [temp count]==2){
        BOOL isSame=NO;
        for(NSString *s in finalArr){
            NSArray *temp2=[s componentsSeparatedByString:@","];
            if(([[temp objectAtIndex:0] isEqualToString:[temp2 objectAtIndex:0]]) || ((((NSString*)[temp objectAtIndex:0])).floatValue-threshhold<=(((NSString*)[temp2 objectAtIndex:0])).floatValue && (((NSString*)[temp objectAtIndex:0])).floatValue+threshhold>=(((NSString*)[temp2 objectAtIndex:0])).floatValue)){
                isSame=YES;
                break;
            }

            if([[temp objectAtIndex:1] isEqualToString:[temp2 objectAtIndex:1]]){
                isSame=YES;
                break;
            }
        }

        if(isSame==NO){
            [finalArr addObject:str];
        }
    }
}
NSLog(@"%@",finalArr);