MKMapView iOS custom user location Annotation not showing/updating position

喜夏-厌秋 提交于 2019-12-11 07:20:07

问题


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;
}

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];

回答1:


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



来源:https://stackoverflow.com/questions/16190920/mkmapview-ios-custom-user-location-annotation-not-showing-updating-position

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!