Get device location (only country) in iOS

NSString *countryCode = [[NSLocale currentLocale] objectForKey: NSLocaleCountryCode]; will get you an identifier like e.g. “US” (United States), “ES” (Spain), etc. In Swift 3: let countryCode = NSLocale.current.regionCode In Swift 2.2: let countryCode = NSLocale.currentLocale().objectForKey(NSLocaleCountryCode) as String Compared to a solution based on CLLocationManager this approach has pros and cons. The primary con is that it … 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

iPhone GPS in background never resumes after pause

If you search for pausesLocationUpdatesAutomatically on the Apple forums you’ll find a recent question along similar lines which has had a response from an Apple developer. I won’t repost it directly here since it is a private forum, but the gist is that the location pausing is for instances when the user forgets that they … 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

Calculating bearing between two CLLocationCoordinate2Ds

Here the code modified with the changes suggested by Oren Trutner and from myself: #define degreesToRadians(x) (M_PI * x / 180.0) #define radiansToDegrees(x) (x * 180.0 / M_PI) – (float)getHeadingForDirectionFromCoordinate:(CLLocationCoordinate2D)fromLoc toCoordinate:(CLLocationCoordinate2D)toLoc { float fLat = degreesToRadians(fromLoc.latitude); float fLng = degreesToRadians(fromLoc.longitude); float tLat = degreesToRadians(toLoc.latitude); float tLng = degreesToRadians(toLoc.longitude); float degree = radiansToDegrees(atan2(sin(tLng-fLng)*cos(tLat), cos(fLat)*sin(tLat)-sin(fLat)*cos(tLat)*cos(tLng-fLng))); if (degree … Read more

didFailWithError: Error Domain=kCLErrorDomain Code=0 “The operation couldn’t be completed. (kCLErrorDomain error 0.)”

If you are using the simulator: Press command + shift + , in Xcode to open the scheme editor Select the Run scheme Go to the Options tab Check ✅ Allow Location Simulation Select a Default Location in the dropdown Selecting None as your Default Location may have caused the problem.

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

Testing CoreLocation on iPhone Simulator

Here is my simple hack that forces the CLLocationMager to return the geocoords of Powell’s Tech Bookstore only on the simulator: #ifdef TARGET_IPHONE_SIMULATOR @interface CLLocationManager (Simulator) @end @implementation CLLocationManager (Simulator) -(void)startUpdatingLocation { CLLocation *powellsTech = [[[CLLocation alloc] initWithLatitude:45.523450 longitude:-122.678897] autorelease]; [self.delegate locationManager:self didUpdateToLocation:powellsTech fromLocation:powellsTech]; } @end #endif // TARGET_IPHONE_SIMULATOR

Location permission alert on iPhone with PhoneGap

You need to do the geolocation after the device is ready. The following Jquery code, for example, will geolocate without that nasty alert: $(function(){ document.addEventListener(“deviceready”, onDeviceReady, false); }) function onDeviceReady() { navigator.geolocation.getCurrentPosition(onSuccess, onError); } function onSuccess(position) { // your callback here } function onError(error) { // your callback here }

tech