cllocationmanager

Swift: Geofencing / geolocations near user location

一世执手 提交于 2019-12-04 14:14:46
Problem: I'm trying to make it so that it uses the user's location all the time and constantly checks to see if it is within 5 miles of the CLLocationCoordinate2D points I have set. If so, it sends a alert if the app is open or a notification if the app is closed. Useful Information: In my project I have 4 swift files: Locations.swift holds the CLLocationCoordinate2D points. Utilities.swift holds a simple alert. UserLocation.swift retrieves and updates the user's location GeoLocationViewController.swift monitors the locations Note: Some code may not be in the right place or relevant, I was

how to trap the location alert response iphone

大兔子大兔子 提交于 2019-12-04 13:03:40
I am using GPS in iphone and it show conformation message for use location service. and i want to trap what user select "Allow" or "No". can any one suggest how i do this? Thank You don't get a direct callback from this alert. However, if the user does not allow Core Location usage, you'll receive a -locationManager:didFailWithError: with a kCLErrorDenied error to your CLLocationManagerDelegate . Since iOS 4.2, you can also listen to -locationManager:didChangeAuthorizationStatus: or check the authorizationStatus of CLLocationManager . This gives you a detailed status. 来源: https://stackoverflow

Find closest longitude and latitude in array from user location - iOS Swift

独自空忆成欢 提交于 2019-12-04 10:51:24
问题 In the question posted here, the user asked: I have an array full of longitudes and latitudes. I have two double variables with my users location. I'd like to test the distance between my user's locations against my array to see which location is the closest. How do I do this? This will get the distance between 2 location but stuggeling to understand how I'd test it against an array of locations. In response, he got the following code: NSArray *locations = //your array of CLLocation objects

How to ask permission from user for second time to allow to access the current location?

自古美人都是妖i 提交于 2019-12-04 10:36:36
In my app, if the user not allowed to access their current location, I can recieve that message in the following method - (void)locationManager:(CLLocationManager*)aManager didFailWithError:(NSError*)anError { switch([anError code]) { case kCLErrorLocationUnknown: break; case kCLErrorDenied: { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Access Denied" message:@"You didn't allow to access your current location" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; break; } } } How to ask the user permission for the second time? I searched and got the answer

didUpdateLocations not being called

折月煮酒 提交于 2019-12-04 10:12:49
I have my object set as the locationManager's delegate, and the didChangeAuthorizationStatus method is called, which does this: func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) { if status == CLAuthorizationStatus.AuthorizedWhenInUse { self.locationManager.startUpdatingLocation() } } I also have this method, which never gets called following this: func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) { if locations.count == 0 { return } //Do stuff } Any thoughts as to why this might not be

Current location in not working in Google Map

左心房为你撑大大i 提交于 2019-12-04 08:12:41
问题 I have integrated google map in swift 3, when map screen appear than current location in not showing, i have added two keys in .plist file and also set CLLocationManager delegate and requestAlwaysAuthorization class MapViewController: UIViewController, CLLocationManagerDelegate, UITextFieldDelegate { @IBOutlet var mapView: GMSMapView! var marker: GMSMarker? override func viewDidLoad() { super.viewDidLoad() self.title = "MapVC" self.doSetupUI() self.searchLocation() } override func

How to detect user selects Don't Allow for MKMapView for iphone

时间秒杀一切 提交于 2019-12-04 07:26:27
I have created a application which uses mapview. For maps I used MKMapKit library. Everything works fine when user selects "Allow" button on alert window. But I want to detect when user selects "Don't Allow". I found a delegate which most of the developers used (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error but the delegate does not get called. Maybe I am missing something. In my header (.h) file I have implemented MKMapViewDelegate . Is there anything else I need to do? Do I need to add some extra classes like CLLocationManager or else. Thanks, In order

Calculating Cumulative elevation gain give me wierd results

蹲街弑〆低调 提交于 2019-12-04 06:41:04
问题 I have the app that use CoreLocation and track user movement. When user is walking or driving I save each coordinate to local database (lat/lng/alt) so I can draw route based on saved coordinates. A few days ago I have added Cumulative elevation gain and I use this code in didLocationUpdate: - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { netElevationGain += MAX(0, oldLocation.altitude - newLocation

Why does CLLocationManager returns null locations on the iphone SDK 4 beta in the Simulator?

烈酒焚心 提交于 2019-12-04 06:16:09
问题 I have this piece of code: - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { NSLog(@"Manager did update location!!"); self.currentLocation = newLocation.description; } I have this code inside a class that conforms to the CLLocationManagerDelegate . I tested earlier in sdk 3.0 and works nice (on both simulator and device). I'm testing this class on the SDK 4, in the simulator, but it gives null as a

iOS Waiting for Location Manager to Init

扶醉桌前 提交于 2019-12-04 04:57:21
I'm developing an iOS app based on the map and location tracking. When the user first boots the app it asks for permission to track location etc. just fine. The only problem is while it's doing that, I have code setting up the initial map view and other location-based variables before the user has clicked OK. I've found I can put these initiation steps after a while loop that waits for the user to change the location manager's permissions as below but this can't possibly be best practice, not to mention it leads to some strange behavior in the transition between the splash screen and the map: