cllocation

What does the const specifier do, before a pointer to object?

半世苍凉 提交于 2019-12-02 00:53:28
If I have a C-string like this: const char* str= "hello"; I know well that I can't change any character of the string because the pointer is const. But if I have this: - (CLLocationDistance)distanceFromLocation:(const CLLocation *)location I can still mutate the object state using it's methods. If the pointer is to a NSMutableString, I'm still able to mutate it. Then what does the const stand for? In that method declaration, location is a pointer to a constant CLLocation . But when you send a message to the location object, the const -ness is not preserved; the method that handles the message

Set annotation's title as current address

[亡魂溺海] 提交于 2019-12-01 22:46:13
I want to get the current location's address and set it to the annotation's title. But it didn't work. I think it's because of the block, but I don't know how to fix it. Any help will be appreciated. The most related code is as following: WhereAmIAnnotation.h #import <Foundation/Foundation.h> #import <MapKit/MapKit.h> @interface WhereAmIAnnotation : NSObject <MKAnnotation> { CLLocation *myLocation; NSString *addr; } @property (nonatomic, retain) CLLocation *myLocation; @property (nonatomic, copy) NSString *addr; @end WhereAmIAnnotation.m #import "WhereAmIAnnotation.h" @implementation

Update a label with speed every x seconds

旧时模样 提交于 2019-12-01 21:53:11
问题 I'm developing my first iPhone application. I have to update a label with the device speed every x seconds. I have created my own CLController and I can get device speed but I don't know if I have got to use NSTimer to update my label. How can I do it? 回答1: You can schedule the timer like this NSTimer *myTimer = [NSTimer scheduledTimerWithTimeInterval:YOUR_INTERVAL target:self selector:@selector(updateLabel) userInfo:nil repeats:YES]; Now below method will get called in every YOUR_INTERVAL

Update a label with speed every x seconds

若如初见. 提交于 2019-12-01 21:00:33
I'm developing my first iPhone application. I have to update a label with the device speed every x seconds. I have created my own CLController and I can get device speed but I don't know if I have got to use NSTimer to update my label. How can I do it? You can schedule the timer like this NSTimer *myTimer = [NSTimer scheduledTimerWithTimeInterval:YOUR_INTERVAL target:self selector:@selector(updateLabel) userInfo:nil repeats:YES]; Now below method will get called in every YOUR_INTERVAL (in seconds) periods - (void) updateLabel { myLabel.text = @"updated text"; } To stop the timer you could call

Updating MKMapView to CLPlacemark returned from CLGeocoder

只愿长相守 提交于 2019-12-01 07:09:28
问题 I want to be able to update the region displayed on a MKMapView by allowing the user to type in an address or location in a UIAlertView. I currently have: if (geocoder.geocoding) [geocoder cancelGeocode]; [geocoder geocodeAddressString:[[alertView textFieldAtIndex:0] text] completionHandler:^(NSArray *placemarks, NSError *error) { if (!error) { NSLog(@"Found a location"); } else { NSLog(@"Error in geocoding"); } NSLog(@"Num found: %d", [placemarks count]); CLPlacemark *placemark = [placemarks

Need to archive CLLocation data

梦想的初衷 提交于 2019-12-01 05:47:05
I have an array of CLLocation data that I would like to archive. Should the NSUserDefaults system be used? Otherwise, how best to archive the CLLocation data? UserDefaults can only store certain types of data, and should be used to store user preference information, not arbitrary application state data. To quote the Apple docs : The NSUserDefaults class provides a programmatic interface for interacting with the defaults system. The defaults system allows an application to customize its behavior to match a user’s preferences. For example, you can allow users to determine what units of

Calculating Distance between two coordinates using CLLocation

倾然丶 夕夏残阳落幕 提交于 2019-12-01 04:40:33
问题 I'm using CLLocationDistance to get the distance between two points, but I'm getting an error when passing my current location in it. CLLocation *current = [[CLLocation alloc] initWithLatitude:startLocation.coordinate.latitude longitude:startLocation.coordinate.longitude]; CLLocation *itemLoc = [[CLLocation alloc] initWithLatitude:[[[getName objectAtIndex:indexPath.row] objectForKey:@"lat"] doubleValue] longitude:[[[getName objectAtIndex:indexPath.row] objectForKey:@"lon"] doubleValue]]; /

iOS Swift - CLGeocoder completionHandler block

旧巷老猫 提交于 2019-12-01 01:59:27
I'm trying to parse a location (CLLocation) into a String. func locationToString (currentLocation: CLLocation) -> String? { var whatToReturn: String? CLGeocoder().reverseGeocodeLocation(currentLocation, completionHandler: { (placemarks: [AnyObject]!, error: NSError!) in if error == nil && placemarks.count > 0 { let location = placemarks[0] as CLPlacemark whatToReturn = "\(location.locality) \(location.thoroughfare) \(location.subThoroughfare)" } }) return whatToReturn } Obviously, whatToReturn always returns null, because completionHandler runs in the background. I'm having a hard time

didUpdateLocation Method Never Called

喜你入骨 提交于 2019-11-30 19:58:22
I am making one app on iphone sdk4.0.In that did update location method never called. I have given my code below.Please help.Thanks in advance. -(id)init { [super init]; obj=[[UIApplication sharedApplication]delegate]; locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; //locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m [locationManager startUpdatingLocation]; return self; } -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *

Getting Altitude(height from sea level) of my location in iphone SDK

僤鯓⒐⒋嵵緔 提交于 2019-11-30 14:25:21
问题 I am trying to get Altitude of my location in my application. But every time I try altitude property of CLLocation object I am getting 0.00 as result. I googled for my query and I got a similar question here and here. This link is saying that if I access CLLocation with wifi or cell tower it will be null. Even if I try to set desireAccuracy to best than even it don't make sure that app will use GPS. It is also saying that if I am indoor that I won't be able to access GPS. I many cases it its