是否可以将CLLocation对象用作字典中的键?当我尝试这样做时,即使有已经插入完全相同经度和纬度的CLLocation键,[dictionary objectForKey:clLocationObj]总是返回nil。我可能做错了什么?使用CLLocation对象作为字典中的键
for (Location *location in someArray) {
CLLocation *locationKey = [[CLLocation alloc] initWithLatitude:[location.latitude doubleValue] longitude:[location.longtitude doubleValue]];
LocationAnnotation *annotationAtLocation = [self.uniqueLocations objectForKey:locationKey];
if (annotationAtLocation == nil)
NSLog(@"this is always nil");
}
我从调试中知道someArray中有多个相同纬度和经度的位置对象。
你解决? – 2011-07-21 09:11:40
我做了一些其他的方式。 CLLocation对我来说效果不好的原因是,它有更多的信息,而不仅仅是lat/long,所以比较2个CLLocations和相同的经纬度不会导致匹配。我最终将CLLocationCoordinate2D对象转换为NSValue,并将其用作字典的关键字。 –