我有一个mapview,其中注释的坐标不断更新,但是当我使用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 { } }]; }
解决方法
更新(以反映解决方案):
拥有自己的自定义注释并实现setCoordinate和/或合成坐标可能会导致问题.
以前的方案:
您只需删除所有注释,然后重新添加它们即可.
[mapView removeAnnotations:[mapView.annotations]]; [mapView addAnnotations:(NSArray *)];
或删除它们并逐个重新添加:
for (id<MKAnnotation> annotation in mapView.annotations) { [mapView removeAnnotation:annotation]; // change coordinates etc [mapView addAnnotation:annotation]; }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。