iOS refresh annotations on mapview

后端 未结 7 1599
悲&欢浪女
悲&欢浪女 2021-01-02 10:01

I have a mapview where the annotation\'s coordinates are constantly being updated but when I use setCoordinate, the annotation does not move. How do I refresh the annotation

相关标签:
7条回答
  • 2021-01-02 11:01

    Try using [self.mapView removeAnnotations:self.mapView.annotations]:

    - (void)viewDidAppear:(BOOL)animated
    {
    
    [super viewDidAppear:animated];
    
    [self.mapView removeAnnotations:self.mapView.annotations];
    
    PFQuery *query = [PFQuery queryWithClassName:@"caches"];
    
    [query findObjectsInBackgroundWithBlock:^(NSArray *comments, NSError *error)
     {
         for (PFObject *comment in comments)
         {
             NSString *tit = comment[@"titulo"];
             NSString *lat = comment[@"latitud"];
             NSString *lon = comment[@"longitud"];
    
             float latFloat = [lat floatValue];
             float lonFloat = [lon floatValue];
    
             CLLocationCoordinate2D Pin;
             Pin.latitude = latFloat;
             Pin.longitude = lonFloat;
             MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc]init];
             annotationPoint.coordinate = Pin;
             annotationPoint.title = tit;
    
             [self.mapView addAnnotation:annotationPoint];
    
         }
    
     }];
    }
    
    0 讨论(0)
提交回复
热议问题