MKMapView iOS自定义用户位置注释未显示/更新位置 [英] MKMapView iOS custom user location Annotation not showing/updating position

查看:138
本文介绍了MKMapView iOS自定义用户位置注释未显示/更新位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在使用自定义注释替换蓝色GPS位置点.我已经将它添加到地图中,就像在viewForAnnotation中一样. OurLocAnnotation类符合MKAnnotation委托.

Hi I am using a custom annotation in replacement of the blue GPS position dot. I have added it to the map like so in the viewForAnnotation. OurLocAnnotation class conforms to MKAnnotation delegate.

    //Custom location view
if([annotation isKindOfClass:[OurLocAnnotation class]]) {
    static NSString *identifier = @"currentLocation";
    SVPulsingAnnotationView *pulsingView = (SVPulsingAnnotationView *)[self.recycleMap dequeueReusableAnnotationViewWithIdentifier:identifier];

    if(pulsingView == nil) {
        pulsingView = [[SVPulsingAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
        pulsingView.annotationColor = [UIColor colorWithRed:0.678431 green:0 blue:0 alpha:1];
        pulsingView.canShowCallout = YES;
    }

    return pulsingView;
}

根据此链接,显示用户位置设置为否":上一个stackoverflow问题,并从viewDidLoad开始调用更新位置

Show user location is set to NO as per this link: Previous stackoverflow question and start updating location is called from viewDidLoad

我的问题是注释未显示,我需要四处移动以使其进入并更新我的位置,还是可以在加载时设置其状态,即显示注释,然后让其将注释更新至我的位置?如果我给注解加上了硬编码的坐标值,那么它会显示出来,但是我不希望我根据自己的位置使用它吗?

The problem I have is the annotation is not showing do I need to move around for it to kick in and update my position or can I set its state on load i.e show the annotation and then have it update the annotation to my location? If I give the annotation hardcoded coordinate values it shows but I don't want that I want it based on my location?

- (void) locationManager:(CLLocationManager*) manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation*)oldLocation
{


if (ourLocAnn == nil)
{
    self.ourLocAnn = [[OurLocAnnotation alloc] init];

    ourLocAnn.title = @"I am here";
    ourLocAnn.coordinate = newLocation.coordinate;
    [recycleMap addAnnotation:ourLocAnn];
}
else
{
    ourLocAnn.coordinate = newLocation.coordinate;
}

更新:我很愚蠢,可以向位置管理器询问我的位置,以显示如下所示的位置.我只是希望当我移动时我的位置会更新....

UPDATE: I am stupid I can show my location like the below by asking the location manager for my position. I have just got to hope my location will update when I move....

ourLocAnn = [[OurLocAnnotation alloc]init];
ourLocAnn.coordinate = clController.locMgr.location.coordinate;
[recycleMap addAnnotation:ourLocAnn];

推荐答案

是的,以上所有代码均有效!终于让它工作了.因此,自定义用户位置的步骤也随您的动作而更新.

Yep all the above code works! Finally got it working. So Steps for custom user loc that also updates with your movements are above.

这篇关于MKMapView iOS自定义用户位置注释未显示/更新位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆