Я прочитал много тем, но я не думаю, что я действительно получаю их.
Я нашел следующий код в одной из тем, но я не уверен, как его поставить. Должен ли я положить в viewdidload? или где-то еще?
И у меня есть большие данные аннотации 3000 точек. Но я не знаю, как читать данные sqlite (я использую данные plist) Пожалуйста, помогите мне.
Заранее спасибо.
// create and populate an array containing all potential annotations
NSMutableArray *allPotentialAnnotations = [NSMutableArray array];
for(all potential annotations)
{
MyAnnotation *myannotation = [[MyAnnotation alloc]
initWithCoordinate:...whatever...];
[allPotentialAnnotations addObject:myannotation];
[myannotation release];
}
// set the user's current location as the reference location
[allPotentialAnnotations
makeObjectsPerformSelector:@selector(setReferenceLocation:)
withObject:mapView.userLocation.location];
// sort the array based on distance from the reference location, by
// utilising the getter for 'distanceFromReferenceLocation' defined
// on each annotation (note that the factory method on NSSortDescriptor
// was introduced in iOS 4.0; use an explicit alloc, init, autorelease
// if you're aiming earlier)
NSSortDescriptor *sortDescriptor =
[NSSortDescriptor
sortDescriptorWithKey:@"distanceFromReferenceLocation"
ascending:YES];
[allPotentialAnnotations sortUsingDescriptors:
[NSArray arrayWithObject:sortDescriptor]];
// remove extra annotations if there are more than five
if([allPotentialAnnotations count] > 5)
{
[allPotentialAnnotations
removeObjectsInRange:NSMakeRange(5,
[allPotentialAnnotations count] - 5)];
}
// and, finally, pass on to the MKMapView
[mapView addAnnotations:allPotentialAnnotations];