0
에 정렬 된 주석의 제한된 수의 표시 나는 500 주석의 NSArray를 가지고 있고 기본적으로 사용자 (나머지는지도보기에 추가되지 않을 것이다)가지도보기
만 열 가까운 주석을 표시하려면 어떻게해야 그렇게? 여기
내 코드입니다 :-(void) loadAndSortPOIs {
[poiArray release];
nextPoiIndex = 0;
NSString *poiPath = [[NSBundle mainBundle] pathForResource:@"annotations"
ofType:@"plist"];
poiArray = [[NSMutableArray alloc] initWithContentsOfFile:poiPath];
CLLocation *homeLocation = [[CLLocation alloc]
initWithLatitude:homeCoordinate.latitude
longitude:homeCoordinate.longitude];
for (int i = 0; i < [poiArray count]; i++) {
NSDictionary *dict = (NSDictionary*) [poiArray objectAtIndex: i];
CLLocationDegrees storeLatitude = [[dict objectForKey:@"workingCoordinate.latitude"] doubleValue];
CLLocationDegrees storeLongitude = [[dict objectForKey:@"workingCoordinate.longitude"] doubleValue];
CLLocation *storeLocation = [[CLLocation alloc]
initWithLatitude:storeLatitude
longitude:storeLongitude];
CLLocationDistance distanceFromHome = [storeLocation distanceFromLocation: homeLocation];
[storeLocation release];
NSMutableDictionary *mutableDict = [[NSMutableDictionary alloc]
initWithDictionary:dict];
[mutableDict setValue:[NSNumber numberWithDouble:distanceFromHome]
forKey:@"distanceFromHome"];
[poiArray replaceObjectAtIndex:i withObject:mutableDict];
[mutableDict release];
}
// now sort by distanceFromHome
NSArray *sortDescriptors = [NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:@"distanceFromHome" ascending:YES] autorelease]];
[poiArray sortUsingDescriptors:sortDescriptors];
NSLog (@"poiArray: %@", poiArray);
[homeLocation release];
편집 :
- (void) displayPois {
[mapView removeAnnotations: mapView.annotations];
for(int i = 0; i < 10; i++) {
NSDictionary *poiDict = [poiArray objectAtIndex:nextPoiIndex++];
CLLocationCoordinate2D poiCoordinate;
poiCoordinate.latitude = [[poiDict valueForKey:@"workingCoordinate.latitude"] doubleValue];
poiCoordinate.longitude = [[poiDict valueForKey:@"workingCoordinate.longitude"] doubleValue];
MyHomeAnnotation *poiAnnotation = [[MyHomeAnnotation alloc]
initWithCoordinate:poiCoordinate
title:[poiDict valueForKey:@"Subtitle"]
];
[mapView addAnnotation:poiAnnotation];
[self loadAndSortPOIs];
[poiAnnotation release];
} [self adjustMapZoom];
}
이 작업을 10 회 반복 할 수 있습니까? 어떻게 그럴 수 있니? \t CLLocationCoordinate2D poiCoordinate; \t poiCoordinate.latitude = [[중요 값 valueForKey : @ "workingCoordinate.latitude"] doubleValue]; \t poiCoordinate.longitude = [[중요 값 valueForKey : @ "workingCoordinate.longitude"] doubleValue]; \t MyHomeAnnotation * poiAnnotation = [MyHomeAnnotation의 ALLOC] \t \t \t \t \t \t \t \t \t initWithCoordinate : poiCoordinate \t \t \t \t \t \t \t \t \t 제목 : poiDict valueForKey @ "자막"] \t \t \t \t \t \t \t \t \t]; \t [mapView addAnnotation : poiAnnotation]; \t [self adjustMapZoom]; \t [poiAnnotation release]; – danskcollignon
예 : for (YourArray의 NSDictionary * poiDict) {여기에있는 귀하의 의견에있는 코드}'. 루프 내에서 adjustMapZoom을 호출하지 않습니다. for-loop 다음에 한 번 호출해야합니다. – Anna
감사합니다. 새로운 코드를 검토해 주시겠습니까? 여전히 작동하지 않습니다 :( – danskcollignon