【问题标题】:Load Annotations from XML after MapView loadsMapView 加载后从 XML 加载注释
【发布时间】:2013-03-05 06:15:04
【问题描述】:

有没有办法先加载MapView 然后用注释填充它?

我问的原因:当我单击首先调用我的 XML 来填充注释的地图时,有一个 延迟,然后视图才会以我的 MapView 打开。

我担心的是,如果 XML 增长,它会进一步延迟或超时。

【问题讨论】:

  • 在使用 XML 加载注释的方法中设置延迟。这将首先加载 mapview,然后在延迟一段时间后开始添加注释。
  • @Dilip,谢谢您的回复。你有例子吗?
  • 在您的 viewDidAppear 方法中调用您的 xml 并准备好经纬度数组...在按钮单击时添加地图,然后将数组传递给您的 viewforannotation 委托......这不会花费时间来打开 mapview。试试看是否有意义..
  • 只是建议如果您可以将可见区域的坐标作为参数包含在webservice中,您可以减少延迟。

标签: iphone objective-c xcode4.5


【解决方案1】:

查看此代码:

#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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多