【发布时间】:2012-12-17 08:51:07
【问题描述】:
我有一个地图视图,其中注释的坐标不断更新,但是当我使用 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 {
}
}];
}
【问题讨论】:
-
这可以通过更改 Annotation 对象中的坐标来完成。它不需要删除注释,然后添加到地图以使更改生效
-
@NakulSudhakar 但它没有改变?
标签: ios annotations mkmapview mkannotation mkannotationview