cllocation

Memory leak from CLLocationManager (CLLocationInternal)

懵懂的女人 提交于 2019-12-12 03:03:14
问题 My app triggers the location update every 10 minutes in a timer, I have declared the location manager as a strong property and synthesized but the CLLocationManager throws the CLLocationInternal leak everytime the location is updated. Is this normal behavior? Log from the xcode instruments 来源: https://stackoverflow.com/questions/15806915/memory-leak-from-cllocationmanager-cllocationinternal

Local Notification on arrival iphone sdk

蓝咒 提交于 2019-12-11 16:02:24
问题 this is my first question here and I am really hoping someone can help me. I have a navigation app that displays an alertview to the user when they arrive at their destination. This works perfectly fine, but I want to alert the user through a localnotification in the same manner when they arrive and the app is in the background. I have registered the app to receive Location updates in the Info.plist file, and do all my distance calculations in didUpdateToLocation. Again, this works perfectly

How to find the long and lat of a city on the iphone?

∥☆過路亽.° 提交于 2019-12-11 03:53:06
问题 I am trying to find the long and lat of a city on the iphone. Say the user is searching for London, I would call some function that would retrieve the long and lat of London. I have looked on the web and found you can use a Google API but there must be an Apple function somewhere to handle this? I have come accross the MKReverseGeocoder which takes the long and lat and tells you what city you are near. e.g. // reverse geocode the user location geocoder = [[[MKReverseGeocoder alloc]

Return NSString which is set from inside a block

梦想的初衷 提交于 2019-12-10 11:33:23
问题 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

Swift 3: reverseGeocodeLocation does not call its completion handler

荒凉一梦 提交于 2019-12-10 10:44:44
问题 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

CLLocationManager holds cache value

冷暖自知 提交于 2019-12-08 05:35:47
问题 This part of code of CLLocationManager is used to calculate the distance travelled. But the location cache is not removed even after using timeIntervalSinceNow . - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { if(newLocation != nil && oldLocation != newLocation) { tempNewLocation = newLocation; tempOldLocation = oldLocation; } NSLog(@"New Location Found"); NSLog(@"- Latitude: %f", newLocation

Saving CLLocation error: Mutating method sent to immutable object

爱⌒轻易说出口 提交于 2019-12-08 05:06:43
问题 I have read the other related questions, but I am stuck. I am trying to save the last known location into a plist for later use. Here is the error message I am receiving: * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFDictionary setObject:forKey:]: mutating method sent to immutable object' Here is my code: var plist = NSDictionary(contentsOfFile: NSBundle.mainBundle().pathForResource("Config", ofType: "plist")) var dataToStore =

How does the distanceFromLocation method work?

风流意气都作罢 提交于 2019-12-07 18:48:05
问题 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

Saving CLLocation error: Mutating method sent to immutable object

限于喜欢 提交于 2019-12-07 17:57:31
I have read the other related questions, but I am stuck. I am trying to save the last known location into a plist for later use. Here is the error message I am receiving: * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFDictionary setObject:forKey:]: mutating method sent to immutable object' Here is my code: var plist = NSDictionary(contentsOfFile: NSBundle.mainBundle().pathForResource("Config", ofType: "plist")) var dataToStore = NSKeyedArchiver.archivedDataWithRootObject(lastKnownLocation) plist.setValue(dataToStore, forKey: "location") The

Reverse function of MKCoordinateRegionMakeWithDistance?

左心房为你撑大大i 提交于 2019-12-07 17:47:09
问题 MapKit's built in function MKCoordinateRegionMakeWithDistance takes distances in meters and turns them into a MKCoordinateRegion : func MKCoordinateRegionMakeWithDistance( _ centerCoordinate: CLLocationCoordinate2D, _ latitudinalMeters: CLLocationDistance, _ longitudinalMeters: CLLocationDistance) -> MKCoordinateRegion is there a reverse function that takes a MKCoordinateRegion and gives me latitudinalMeters and longitudinalMeters? 回答1: MKCoordinateRegion gives a center (latitude and