iOS刷新mapview上的注释

iOS刷新mapview上的注释,第1张

概述我有一个mapview,其中注释的坐标不断更新,但是当我使用setCoordinate时,注释不会移动.如何刷新注释以反映其坐标? - (void)updateUnits { PFQuery *query = [PFQuery queryWithClassName:@"devices"]; [query whereKeyExists:@"location"]; [quer 我有一个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和/或合成坐标可能会导致问题.

资料来源:http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/LocationAwarenessPG/AnnotatingMaps/AnnotatingMaps.html

以前的方案:

您只需删除所有注释,然后重新添加它们即可.

[mapVIEw removeAnnotations:[mapVIEw.annotations]];[mapVIEw addAnnotations:(NSArray *)];

或删除它们并逐个重新添加:

for (ID<MKAnnotation> annotation in mapVIEw.annotations){    [mapVIEw removeAnnotation:annotation];    // change coordinates etc    [mapVIEw addAnnotation:annotation]; }
总结

以上是内存溢出为你收集整理的iOS刷新mapview上的注释全部内容,希望文章能够帮你解决iOS刷新mapview上的注释所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1102703.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存