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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:23:47+00:00 2026-06-08T10:23:47+00:00

I’ve been tackling this for a while, and I need some help designing my

  • 0

I’ve been tackling this for a while, and I need some help designing my logic.

I want to do three things in this order
1) Get the user’s location
2) Call a web service with that user’s location
3) load the user interface with results

I want this to be designed in a way that makes it simple for me to refresh the results, so if the user presses a refresh button, I do steps 1-3 again.

Right now, I do it as follows. This is my code in my ViewController.

- (void) viewDidLoad {
    //initialize CLLocationManager
    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    self.locationManager.delegate = self;
    [self.locationManager startUpdatingLocation];

- (void) locationManager: (CLLocationManager *)manager 
     didUpdateToLocation: (CLLocation *)newLocation
            fromLocation:(CLLocation *)oldLocation
{
    if (oldLocation!= nil) { // make sure to wait until second latlong value
        [self setLatitude:newLocation.coordinate.latitude];
        [self setLongitude: newLocation.coordinate.longitude];
        [self.locationManager stopUpdatingLocation];
        self.locationManager.delegate = nil;
        [self makeUseOfLocationWithLat:[self getLatitude] andLon:[self getLongitude]];
}

- (void) makeUseOfLocationWithLat: (double) lat andLon: (double) lon {
    // call web service
    [self loadUI];
}

- (void) loadUI {
     // loads the user interface
}

Correct me if I’m wrong, but my design is really bad. It’s not modular at all, each method is tied to each other. Also, I’m doing intensive web service calls in my ViewController, as opposed to in any model classes. How do you set this up properly? One of the major issues I have is… I don’t know when my latitude and longitude variables get their values. If I don’t call makeUseOfLocation from my delegate method, then I end up calling makeUseOfLocation with nil values of latitude and longitude.

I’ve looked into singletons for my location managing, NSKeyValueObserving Protocols, dispatch_queues, NSOperations, but I’m new to developing on iOS, and I’m getting stuck somewhere with whatever I try. Please let me know your thoughts on how to set this up.

Thanks for your time, I really appreciate it.

  • 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-08T10:23:49+00:00Added an answer on June 8, 2026 at 10:23 am

    If you really want to separate it, as an easy first step, I would do the following:

    • Create a new class, something like LocationTracker
    • Make LocationTracker the CLLocationManager’s delegate, likely in it’s init method
    • Have LocationTracker subscribe to the NSNotification “myapp.location.refresh”
    • Have your ViewController subscribe to “myapp.location.updated”
    • When a CLLocationManager gives a didUpdate, publish “myapp.location.updated”
    • When your refresh button is pressed, publish “myapp.location.refresh”
    • When “myapp.location.refresh” is notified, force an update

    This creates a small protocol between your location tracking class and the controller. The NSNotification docs are pretty good, they’ll get you there.

    You could have the controller own the instance, or the application delegate. I don’t think a singleton is really all that necessary.

    You could also use key-value observing, or a protocol/delegate type setup, any of them will work as they’re all basically the same pattern (Observer).

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.