1
votes

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
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.user467105
@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.Alex McPherson
@AnnaKarenina I can confirm it all works and thanks to you you supplied a clue to getting this to work....Alex McPherson

1 Answers

1
votes

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