简体   繁体   中英

Load Annotations from XML after MapView loads

Is there a way to load the MapView first then fill it with the annotations?

Reason why I ask: When I click on my map which calls my XML first to fill the annotations, there is a delay and only then does the View open with my MapView .

My concerns are that if the XML grows, it would delay even further or timeout.

See this code:

#import "MapViewController.h"
#import "MapViewAnnotation.h"

@implementation MapViewController

@synthesize mapView;

// When the view loads
- (void)viewDidLoad
{

    [self performSelector:@selector(addAnnotation) withObject:@"" afterDelay:5.0];
}

//here i am delaying my annotation to 5 second so my map can first display

-(void)addAnnotation
{
    // Set some coordinates for our position (Buckingham Palace!)
    CLLocationCoordinate2D location;
    location.latitude = (double) 51.501468;
    location.longitude = (double) -0.141596;

    // Add the annotation to our map view
    MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"Buckingham Palace" andCoordinate:location];
    [self.mapView addAnnotation:newAnnotation];
    [newAnnotation release];
}

// When a map annotation point is added, zoom to it (1500 range)
- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views
{
    MKAnnotationView *annotationView = [views objectAtIndex:0];
    id <MKAnnotation> mp = [annotationView annotation];
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate], 1500, 1500);
    [mv setRegion:region animated:YES];
    [mv selectAnnotation:mp animated:YES];
}

// Received memory warning
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

// If the view unloads, release the map view
- (void)viewDidUnload {
    [super viewDidUnload];
    [mapView release];
    mapView = nil;
}

// Deallocations
- (void)dealloc {
    [mapView release];
    [super dealloc];
}

@end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM