我有一个地图视图,在这个视图中注释的坐标会不断更新,但是当我使用 setCoordinate 方法时,注释并没有移动。我该如何刷新注释以反映它们的坐标?
- (void)updateUnits {
PFQuery *query = [PFQuery queryWithClassName:@"devices"];
[query whereKeyExists:@"location"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
for (PFObject *row in objects) {
PFGeoPoint *geoPoint = [row objectForKey:@"location"];
CLLocationCoordinate2D coord = { geoPoint.latitude, geoPoint.longitude };
for (id<MKAnnotation> ann in mapView.annotations) {
if ([ann.title isEqualToString:[row objectForKey:@"deviceid"]]) {
[ann setCoordinate:coord];
NSLog(@"latitude is: %f" , coord.latitude);
NSLog(@"Is called");
break;
}
else {
//[self.mapView removeAnnotation:ann];
}
}
}
}
else {
}
}];
}