Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS Core Location Set Pin to user location in viewDidLoad
    primarykey
    data
    text
    <p>I am attempting to set a map annotation to the user's current location. I am trying to set the pin in the viewDidLoad method, however because the method</p> <pre><code>- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation </code></pre> <p>Has not been called yet, the lat and long are 0.000000. Is there a way to call this method in my viewDidLoad or any other solution that will make a pin appear at my beginning location when the application loads?</p> <p><strong>UPDATE, Added Annotation Code</strong></p> <pre><code>CLLocationCoordinate2D theCoordinate; theCoordinate.latitude = (_currentLocation.latitude); theCoordinate.longitude = (_currentLocation.longitude); NSLog(@"The Coordinate Value:"); NSLog(@"%f, %f",theCoordinate.latitude,theCoordinate.longitude); DDAnnotation *annotation = [[[DDAnnotation alloc] initWithCoordinate:theCoordinate addressDictionary:nil] autorelease]; annotation.title = @"Drag to Move Pin"; annotation.subtitle = [NSString stringWithFormat:@"%f %f", annotation.coordinate.latitude, annotation.coordinate.longitude]; [self.mapView addAnnotation:annotation]; </code></pre> <p><strong>UPDATE 2</strong> Still not working, code is in the didUpdateLocation Method</p> <pre><code>static BOOL annotationAdded = NO; if (!annotationAdded) { annotationAdded = YES; CLLocationCoordinate2D theCoordinate; theCoordinate.latitude = _currentLocation.latitude; theCoordinate.longitude = _currentLocation.longitude; //Sets Initial Point to Africa Because Method to obtain current Location //Hasen't Fired when View Loads theCoordinate.latitude = (mapView.userLocation.coordinate.latitude); theCoordinate.longitude = (mapView.userLocation.coordinate.longitude); NSLog(@"The Coordinate Value:"); NSLog(@"%f, %f",theCoordinate.latitude,theCoordinate.longitude); DDAnnotation *annotation = [[[DDAnnotation alloc] initWithCoordinate:theCoordinate addressDictionary:nil] autorelease]; annotation.title = @"Drag to Move Pin"; annotation.subtitle = [NSString stringWithFormat:@"%f %f", annotation.coordinate.latitude, annotation.coordinate.longitude]; [self.mapView addAnnotation:annotation]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload