0

我将注释作为硬编码值添加到方法中

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation

     CLLocationCoordinate2D coords1;
     coords1.latitude = 40.579754;
     coords1.longitude = -120.1303229;

     MKPointAnnotation *annotationPoint1 = [[MKPointAnnotation alloc] init];
     annotationPoint1.coordinate = coords1;
     annotationPoint1.title = @"TJ11234";
     annotationPoint1.subtitle = @"Power Failure \n Start Time:12hrs 30min \n End Time:14hrs ";

     [self.mapView addAnnotation:annotationPoint1];

使用 lats 和 longitude 硬编码的值最初可以很好地加载,但是当我转到另一个页面并返回该页面时,注释没有加载。我应该怎么做才能纠正它?

4

1 回答 1

0

mapView:didUpdateUserLocation:每当地图视图接收到新的位置更新时调用。检查文档

如果您想在显示地图时设置注释,您可以将代码放入viewDidAppear或类似的地方。

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated]

    CLLocationCoordinate2D coords1;
    coords1.latitude = 40.579754;
    coords1.longitude = -120.1303229;

    MKPointAnnotation *annotationPoint1 = [[MKPointAnnotation alloc] init];
    annotationPoint1.coordinate = coords1;
    annotationPoint1.title = @"TJ11234";
    annotationPoint1.subtitle = @"Power Failure \n Start Time:12hrs 30min \n End Time:14hrs ";

    [self.mapView addAnnotation:annotationPoint1];
}

希望这可以帮助。

于 2013-05-27T16:14:23.180 回答