What’s the easiest way to get the current location of an iPhone?

What I do is implement a singleton class to manage updates from core location. To access my current location, I do a CLLocation *myLocation = [[LocationManager sharedInstance] currentLocation]; If you wanted to block the main thread you could do something like this: while ([[LocationManager sharedInstance] locationKnown] == NO){ //blocking here //do stuff here, dont forget … Read more

Why the CLLocationManager delegate is not getting called in iPhone SDK 4.0?

I had a similar error, and is solved now. The issue is declaring locationManager variable locally. Declare it instead as a class variable and make sure it is retained either directly or via property retain (or strong if you use ARC). That solves the problem! The issue was de locationManager variable was released and never … Read more

How to find your current location with CoreLocation

You can find your location using CoreLocation like this: import CoreLocation: #import <CoreLocation/CoreLocation.h> Declare CLLocationManager: CLLocationManager *locationManager; Initialize the locationManager in viewDidLoad and create a function that can return the current location as an NSString: – (NSString *)deviceLocation { return [NSString stringWithFormat:@”latitude: %f longitude: %f”, locationManager.location.coordinate.latitude, locationManager.location.coordinate.longitude]; } – (void)viewDidLoad { locationManager = [[CLLocationManager alloc] … Read more

iOS Geofence CLCircularRegion monitoring. locationManager:didExitRegion does not seem to work as expected

I don’t think region monitoring will work well for such a small radius. The best accuracy with the GPS chip and kCLLocationAccuracyBestForNavigation is often just 10 meters. Apple says (in the Location & Maps PG) that the minimum distance for regions should be assumed to be 200m I’ve heard that region monitoring is using WiFi … Read more

Behaviour for significant change location API when terminated/suspended?

Since I asked this question, I have done a fair bit of testing (mostly on the train between home and work) and have confirmed that the behaviour for suspended apps is as I suspected at the end of the question. That is, your suspended app is woken up, you don’t receive any callbacks on your … Read more

CLLocation Category for Calculating Bearing w/ Haversine function

Your code seems fine to me. Nothing wrong with the calculous. You don’t specify how far off your results are, but you might try tweaking your radian/degrees converters to this: double DegreesToRadians(double degrees) {return degrees * M_PI / 180.0;}; double RadiansToDegrees(double radians) {return radians * 180.0/M_PI;}; If you are getting negative bearings, add 2*M_PI to … Read more

iOS HTTP request while in background

It can be done but it is unreliable because you ask the OS for time to send something and it can accept or deny your request. This is what I have (stolen from somewhere on SO): […] //we get the new location from CLLocationManager somewhere here BOOL isInBackground = NO; if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) … Read more

Moving a CLLocation by x meters

A conversion to Swift, taken from this answer: func locationWithBearing(bearingRadians:Double, distanceMeters:Double, origin:CLLocationCoordinate2D) -> CLLocationCoordinate2D { let distRadians = distanceMeters / (6372797.6) // earth radius in meters let lat1 = origin.latitude * M_PI / 180 let lon1 = origin.longitude * M_PI / 180 let lat2 = asin(sin(lat1) * cos(distRadians) + cos(lat1) * sin(distRadians) * cos(bearingRadians)) let … Read more