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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:56:18+00:00 2026-06-15T10:56:18+00:00

I have a simple locations map and I want to make my app beep

  • 0

I have a simple locations map and I want to make my app beep when the user is approaching a location that is listed in a remote file

the listed locations are on my server named locations.txt

how can i check locations.txt every 1 minute to see if the user is within 300m of a location??

  • 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-15T10:56:19+00:00Added an answer on June 15, 2026 at 10:56 am

    The standard answer to this question is Shape-Based Regions as described in the Location Awareness Guide. Generally, shape-based regions is the way to go if you have a limited number of regions. But, given that you want a lot of regions, you might have to “roll your own”:

    • Turn on a location service and monitor your location. See the Location Awareness Programming Guide. If you use standard location service, make sure to set a desiredAccuracy that is as low as possible to achieve the functional need (e.g. kCLLocationAccuracyHundredMeters).

    • Once you’ve successfully received the first didUpdateLocations, if you really want to check every minute, you could create a timer at that point. If the purpose of that timer is to just check the users’ location, then the timer is really not needed and you can just wait for occurrences of the didUpdateLocations.

    • You can iterate through your array of locations to monitor (I’d convert them to CLLocation objects) and simply use distanceFromLocation.

    A couple of observations, though:

    • You suggest that you want to check locations.txt every minute to see if user is within 300m of location. I can imagine two reasons why you might have proposed that solution:

      • Did server’s locations.txt change? If this is the problem you’re trying to solve, a better solution would be push notifications (a.k.a. “remote notifications”) and you want to make sure the client has access to the latest information. The process of constantly re-retrieving the file is very expensive (in terms of bandwidth, battery, computationally); or

      • Did the user move? If you’re concerned about whether the user may have moved, the right solution is not to check every minute, but rather wait for the [CLLocationManagerDelegate] instance method didUpdateLocations to be called. If you want to avoid too many redundant checks, you can always keep track of whether the last request took place less than a minute ago or not, and then only check again if it was more than a minute ago. But that’s very different than checking every minute whether you need to or not.

    • You’ve suggested using a text file. You might want to contemplate using a JSON file (or XML file), which is a better mechanism for retrieving data from a server.


    For example, if you have a text file in JSON format, you can parse the results in another single line of code (JSONObjectWithData). To illustrate, let me show you what a JSON file might look like (where the square brackets designate an array, and the curly braces designate a dictionary, this is therefore an array of dictionaries):

    [
      {
        "name" : "Battery Park",
        "latitude" : 40.702,
        "longitude" : -74.015
      },
      {
        "name" : "Grand Central Station",
        "latitude" : 40.753,
        "longitude" : -73.977
      }
    ]
    

    Then your app can retrieve the results incredibly easily with two lines:

    NSData *locationsData = [NSData dataWithContentsOfURL:url];
    NSArray *locationsArray = [NSJSONSerialization JSONObjectWithData:locationsData options:0 error:&error];
    

    So, you’ll need to start location services:

    if (nil == self.locationManager)
       self.locationManager = [[CLLocationManager alloc] init];
    
    self.locationManager.delegate = self;
    self.locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
    
    // Set a movement threshold for new events.
    self.locationManager.distanceFilter = 500;
    
    [self.locationManager startUpdatingLocation];
    

    You’ll then have a routine for checking the current location:

    - (void)checkLocation
    {
        NSURL *url = [NSURL URLWithString:kLocationsUrlString];
        NSData *locationsData = [NSData dataWithContentsOfURL:url];
        NSAssert(locationsData, @"failure to download data"); // replace this with graceful error handling
    
        NSError *error;
        NSArray *locationsArray = [NSJSONSerialization JSONObjectWithData:locationsData
                                                                  options:0
                                                                    error:&error];
        NSAssert(locationsArray, @"failure to parse JSON");   // replace with with graceful error handling
    
        for (NSDictionary *locationEntry in locationsArray)
        {
            NSNumber *longitude = locationEntry[@"longitude"];
            NSNumber *latitude = locationEntry[@"latitude"];
            NSString *locationName = locationEntry[@"name"];
    
            CLLocation *location = [[CLLocation alloc] initWithLatitude:[latitude doubleValue]
                                                              longitude:[longitude doubleValue]];
            NSAssert(location, @"failure to create location");
    
            CLLocationDistance distance = [location distanceFromLocation:self.locationManager.location];
    
            if (distance <= 300)
            {
                NSLog(@"You are within 300 meters (actually %.0f meters) of %@", distance, locationName);
            }
            else
            {
                NSLog(@"You are not within 300 meters (actually %.0f meters) of %@", distance, locationName);
            }
        }
    }
    

    And this will be called when the user’s location changes:

    // this is used in iOS 6 and later
    
    - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
    {
        [self checkLocation];
    }
    
    // this is used in iOS 5 and earlier
    
    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
    {
        if ([[[UIDevice currentDevice] systemVersion] floatValue] < 6.0)
            [self checkLocation];
    }
    

    The implementation might look like this test project on GitHub. This is a barebones implementation, but it gives you an idea of the tools you have at hand, namely retrieving your locations.json file and comparing that to the location retrieved by the device.

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

Sidebar

Related Questions

I have a simple app that will allow a user to tag a location.
I want to make an html5-based webpage for mobile devices that shows a map
I want to get the user's current location from my iPhone app. I want
let's say i want to build a smartphone app that tells a user when/where
I have developed a simple location aware iPhone application which is functionally working very
I have simple php validation form that is halfway working. If you leave the
I have simple win service, that executes few tasks periodically. How should I pass
I have a simple goal: Map Ctrl-C, a command I don't think I've ever
Greetings, I want to write a script that handles simple http requests from Google
I have this code that shows the current location as being specified in the

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.