Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6133975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:17:53+00:00 2026-05-23T17:17:53+00:00

I am attempting to set a map annotation to the user’s current location. I

  • 0

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

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

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?

UPDATE, Added Annotation 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];

UPDATE 2
Still not working, code is in the didUpdateLocation Method

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];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:17:53+00:00Added an answer on May 23, 2026 at 5:17 pm

    MKMapView automatically places an annotation of class MKUserLocation when you set mapView.showsUserLocation = YES.

    You can replace the default view for this annotation to whatever default annotation view you want by doing this in mapView:viewForAnnotation::

    - (MKAnnotationView *) mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation {
        if ([annotation isKindOfClass:[MKUserLocation class]]) {
            // replace the following with code to generate and return custom user position annotation view
            return customAnnotationView;
        }
    
        //*** other code ***//
    }
    

    Update:

    If all you want to do is set a pin initially (once) at the user’s location when the view loads, then you will have to wait until the phone can grab the data you need since that takes some time. Add your annotation in mapView:didUpdateUserLocation the first time it is called, and that should do the trick:

    - (void) mapView:(MKMapView *)theMapView didUpdateUserLocation:(MKUserLocation *)userLocation {
        static BOOL annotationAdded = NO;
    
        if (!annotationAdded) {
            annotationAdded = YES;
            //*** add annotation to mapView ***//
        }
    }
    

    Final Comment:

    I would generally avoid setting a static pin at a users location the first time this method is called, however, and instead opt to just using the default standard blue dot. That is because the location services in the phone take time to find an accurate reading on the user’s location, but in the interest of time it will send you location updates as soon as possible. This means that the first location update may not be very accurate, but subsequent updates may be much more accurate. That is why the standard blue dot sometimes changes position frequently within the first few moments of showing up on the map.

    Just a caveat. Obviously what you choose to do depends on what the purpose of your app is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to set an asp.net textbox to a SQL 2005 money data
I'm attempting to set up a symbol proxy using symproxy.dll from Debugging Tools for
I am attempting to set a value in a textarea field using jquery with
I'm attempting to set up basic logging to the windows event log in .net
I am attempting to set up my own project using a third party library
I have a Perl script that I'm attempting to set up using Perl Threads
Possible Duplicate: C# generic constraint for only integers Greets! I'm attempting to set up
I am attempting to run the following command in KornShell (ksh): set -A INDEXES
I am attempting to use the code-behind (Page_Load or PreRender) to set a date-time
I'm attempting to check if a value exists in the choices tuple set for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.