自定义当前位置注释图钉未随核心位置更新
尝试为当前位置添加自定义图钉,但位置未更新。即使在设置 setShowsUserLocation = YES;
之后
- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
if ([[annotation title] isEqualToString:@"Current Location"]) {
self.image = [UIImage imageNamed:[NSString stringWithFormat:@"cursor_%i.png", [[Session instance].current_option cursorValue]+1]];
}
,但是,如果我设置为 return nil;
一切正常,但我丢失了自定义图像。我真的很想让这个发挥作用。任何帮助将不胜感激。
Trying to add a custom pin for current location, However the location does not update. Even after setting setShowsUserLocation = YES;
- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
if ([[annotation title] isEqualToString:@"Current Location"]) {
self.image = [UIImage imageNamed:[NSString stringWithFormat:@"cursor_%i.png", [[Session instance].current_option cursorValue]+1]];
}
However, if I set to return nil;
everything works fine, but I lose the custom image. I really want to get this to work. Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您所看到的,setShowsUserLocation 标志仅使用默认的蓝色气泡显示当前位置。
您需要执行的操作是监听手机的位置更新,并自行手动重新定位注释。您可以通过创建 CLLocationManager 实例来完成此操作,并在位置管理器通知其委托更新时删除并替换您的注释:
为了重新定位坐标,我有一个类 Placemark,它符合协议 MKAnnotation:
然后在我的地图视图控制器中我将注释放置在:
As you've seen the setShowsUserLocation flag only shows the current location using the default blue bubble.
What you need to do here listen for location updates from the phone and manually reposition your annotation yourself. You can do this by creating a CLLocationManager instance and remove and replace your annotation whenever the Location Manager notifies its delegate of an update:
To reposition the coordinates, I have a class, Placemark, that conforms to the protocol MKAnnotation:
Then in my mapview controller I place the annotation with: