cllocation

iphone - What consumes less battery? StartmonitoringLocationsChanges or startmonitoringforregion?

会有一股神秘感。 提交于 2019-12-07 14:37:19
问题 I would like you to give me your feedback on which method consumes less battery. My app will run in the background and will wake up with location changes, so I would like to use the method that consumes less battery. Any ideas on which one it is? Thanks 回答1: Neither of these choices is responsible for more or less battery consumption. In order for your app to be notified of any location update, regardless of whether it is for a region change or a significant location change, you must specify

Can I get the accuracy of GPS location in iOS?

核能气质少年 提交于 2019-12-07 06:54:08
问题 I've seen Android developers get the accuracy of a GPS location. Is there a way that I can get the accuracy of my currenct GPS location in iOS? I am using the code from this answer to get my location: locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; locationManager.distanceFilter = kCLDistanceFilterNone; locationManager.desiredAccuracy = kCLLocationAccuracyBest; [locationManager startUpdatingLocation]; - (void)locationManager:(CLLocationManager *)manager

calculate distance between 2 coordinates iphone - best practice

冷暖自知 提交于 2019-12-06 15:25:55
问题 I'm finishing an App in wish i need to show the user the distance between him and about 500 coordinates. using the CLLocation method to calculate it, works well, but it takes about 1 minute in iPhone 4 to finish calculations for each location. What is the best way to do it? Using span? Any other faster way? Thanks all, rui 回答1: I think Sahgal is right, here is some code, perhaps it will help you. +(CGFloat)calculateDistanceBetweenSource:(CLLocationCoordinate2D)firstCoords andDestination:

Swift 3: reverseGeocodeLocation does not call its completion handler

我们两清 提交于 2019-12-06 13:33:56
This is my code if loc.latitude != 0.0 && loc.longitude != 0.0 { let loca = CLLocation(latitude: loc.latitude, longitude: loc.longitude) geoCoder.reverseGeocodeLocation(loca) { (placemarks, error) in // this is the last line that is being called var placemark : CLPlacemark! placemark = placemarks?[0] city = (placemark.addressDictionary?["City"] as! String) } } Execution of this code snippet in my app goes right, no runtime errors occurred. However, the last line that is being called is geoCoder.reverseGeocodeLocation(loca){(placemarks, error) I also double checked that loca is not nil. Why

iPhone Brainstorm - CLLocation in Background - Polling every 15 minutes

荒凉一梦 提交于 2019-12-06 10:47:36
问题 Here is the scenario. I need to have an application which polls a web service with the users location every 15 minutes whether in background / foreground. At the moment I: Start / Restart the location manager with accuracy highest and distance filter none. Wait to get within desired accurancy. Store reading setDesiredAccuracy to be: "kCLLocationAccuracyThreeKilometers" setDistanceFilter to be: 1000 Set a performSelector:@selector(getLocation) withObject:nil afterDelay:900 Start again from

Location timestamp accuracy in ios

一个人想着一个人 提交于 2019-12-06 10:24:40
After analysing location services in iOS 10, found that some inconsistency is in the caching behaviour. Fetching locations in a periodic time (in my case every 20 secs) returns locations but their timestamps are not in chronologically ordered. This indicates that the caching locations might have issues. So if you are checking accuracy through location-timestamp better to save the previous timestamps also. So that you could decide that the location fetched can be used or not. Below image is taken from my console log. Here I used the format "Lat Long : latitude_longitude | location_timestamp |

Return NSString which is set from inside a block

点点圈 提交于 2019-12-06 07:51:35
I have a method which looks like this: -(NSString *)getCityFromLocation:(CLLocation *)location { __block NSString *city; CLGeocoder *geocoder = [[CLGeocoder alloc] init]; [geocoder reverseGeocodeLocation: location completionHandler: ^(NSArray *placemarks, NSError *error) { //Get address CLPlacemark *placemark = [placemarks objectAtIndex:0]; city = [placemark.addressDictionary objectForKey:@"City"]; NSLog(@"city 1: %@", city); }]; return city; } And I call it like this: NSString *city = [self getCityFromLocation:currentLocation]; NSLog(@"city 2: %@", city); In NSLog, I get: city 2: (null) city

How does the distanceFromLocation method work?

做~自己de王妃 提交于 2019-12-06 07:45:45
I frequently use the distanceFromLocation method for CLLocation objects to get their distance from other locations. Enumerating through an array of CLLocations, I then compare each to my reference location using this method. I'm curious to know the processing/memory implications for using distanceFromLocation , especially for a large number of CLLocation objects in succession. How does this method work - does it connect to the server to get the data, or does it calculate the distance based on some mathematical formula, such as the Haversine Formula ? Is there a more efficient method to compare

CLGeocoder reverse geocoding fails with Error Domain=NSURLErrorDomain Code=-1000 -

不问归期 提交于 2019-12-06 00:44:01
问题 With a CLLocation object (content e.g. latitude = 48.196169, longitude = 11.620237), I try to get the current city and country like: if(!geocoder) { geocoder = [[CLGeocoder alloc] init]; } if (geocoder.geocoding) [geocoder cancelGeocode]; [geocoder reverseGeocodeLocation:lo completionHandler:^(NSArray *placemarks, NSError *error) { if(devMode) { NSLog(@"Found placemarks: %@, error: %@", placemarks, error); } if (error == nil && [placemarks count] > 0) { // MY CODE - here placemarks is always

How to get lat and long coordinates from address string

自闭症网瘾萝莉.ら 提交于 2019-12-05 21:46:11
问题 I have a MKMapView that has a UISearchBar on the top, and I want the user to be able to type a address, and to find that address and drop a pin on it. What I don't know is how to turn the address string into longitude and latitude, so I can make a CLLocation object. Does anyone know how I can do this? 回答1: You may find your answer in this question. iOS - MKMapView place annotation by using address instead of lat / long By User Romes. NSString *location = @"some address, state, and zip";