我有一个 NSMutableArray 存储 ID、纬度、经度等...我需要将用户的当前位置与下面数组中存储的项目的纬度和经度进行比较。
我知道如何获取用户的当前坐标,但我不知道如何访问数组中的坐标或如何比较距离。
该数组是一个名为 scrolledPast 的 NSMutableArray(见下文)。假设当前用户的坐标是 21.31,-157.86。我该怎么开始?任何指导将不胜感激。谢谢你的帮助!
array: (
{
key1 = 80;
key2 = "11:34 PM";
key3 = "place1";
key4 = "21.3111656";
key5 = "-157.8606953";
},
{
key1 = 251;
key2 = "11:34 PM";
key3 = "place2";
key4 = "21.310672";
key5 = "-157.8611839";
},
{
key1 = 79;
key2 = "11:34 PM";
key3 = "place3";
key4 = "21.3106798";
key5 = "-157.8612934";
}
)
这是生成上述数组的代码:
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setObject:placeId forKey:@"key1"];
[dict setObject:currentTime forKey:@"key2"];
[dict setObject:textForMyLabel forKey:@"key3"];
[dict setObject:placeLatitude forKey:@"key4"];
[dict setObject:placeLongitude forKey:@"key5"];
[scrolledPast addObject:dict];
NSLog(@"array: %@", scrolledPast);