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 7810531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:49:02+00:00 2026-06-02T03:49:02+00:00

I have a method in my appDelegate which gets latitude and longitude and returns

  • 0

I have a method in my appDelegate which gets latitude and longitude and returns a string which I can use in any viewController.

AppDelegate :

-(void)StartUpdating
{    
    locManager = [[CLLocationManager alloc] init];
    locManager.delegate = self;
    locManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
    locManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
    [locManager startUpdatingLocation];
}

#pragma mark 
#pragma mark locationManager delegate methods 


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

    float latitude = newLocation.coordinate.latitude;
    strLatitude = [NSString stringWithFormat:@"%f",latitude];
    float longitude = newLocation.coordinate.longitude;
    strLongitude = [NSString stringWithFormat:@"%f", longitude];
    //[self returnLatLongString:strLatitude:strLongitude];

}

-(NSString*)returnLatLongString
{    
    NSString *str = @"lat=";
    str = [str stringByAppendingString:strLatitude];
    str = [str stringByAppendingString:@"&long="];
    str = [str stringByAppendingString:strLongitude];

    return str;
}

I am calling StartUpdating in start of application. Now in my viewController I call this method:

AppDelegate *appDelegate=[AppDelegate sharedAppDelegate];
NSString *str = [appDelegate returnLatLongString];  

But I get a crash in

str = [str stringByAppendingString:strLatitude];  

in returnLatLongString.

I know I am getting crash because there is no value in strLatitude at that time. But how can I fix this? How can I still have updated value of latitude and longitude?

Also, I don’t want to use locationManager in viewControllers. So that I can get current location in all viewControllers, I did it in appDelegate.

  • 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-06-02T03:49:04+00:00Added an answer on June 2, 2026 at 3:49 am

    The crash might be because str is an NSString, and so therefore is not mutable. Assigning it back to itself in this case is problematic. It would be simpler just to use stringWithFormat:

    NSString *str = [NSString stringWithFormat: @"lat=%@&long=%@", strLatitude, strLongitude];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have this method: -(void)seperateGuides { DLog(GetGuideListCount: %i, [[appDelegate getGuideList] count]); columnOneArray =
I have an Obj-C method similar to this: -(void)getUserDefaults:(BOOL *)refreshDefaults { PostAppDelegate *appDelegate =
in my appdelegate i have method which shows the Default.png for 3 seconds(splashscreen): -
I create small application which is media player. I have method where I have
I have a method in my application which retrieves the last saved image in
I have a method called handleLocalNotification in my AppDelegate that fires when my app
In my app, I have implemented a private method in my AppDelegate to override
I have one class called MainMenu, which has a method called switchViews, with 2
I have two string properties setup in my cocoa application's app delegate which are
I have an array declared inside a user defined method. I use this array

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.