2013-05-27 61 views
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]; 

與拉特的價值觀和經度硬編碼intially其裝載很好,但是當我去到另一個網頁,回來的頁面註釋未加載。我應該怎麼做才能糾正它?

回答

0

mapView:didUpdateUserLocation:在地圖視圖收到新位置更新時調用。檢查documentation

如果要在顯示地圖時設置註釋,可以將代碼放在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]; 
} 

希望這會有所幫助。