MKMapView iOS custom user location Annotation not showing/updating position
Asked Answered
G

1

1

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];
Graphemics answered 24/4, 2013 at 11:34 Comment(3)
The posted code looks fine and setting it to newLocation.coordinate should work. You should be able to test it in the simulator using Debug\Location\FreewayDrive. NSLog the coordinates that you get in didUpdateToLocation.Barthol
@AnnaKarenina many thanks for taking the time to look thats kind. I will try the simulator method or take a walk around to see if she updates ok with my custom user location annotation.Graphemics
@AnnaKarenina I can confirm it all works and thanks to you you supplied a clue to getting this to work....Graphemics
G
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.

Graphemics answered 26/4, 2013 at 14:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.