Guest User

Untitled

a guest
Oct 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.78 KB | None | 0 0
  1. @property (readonly) CLLocationCoordinate2D coordinate;
  2. typedef {
  3. CLLocationDegrees latitude; //a double
  4. CLLocationDegrees longtitude; //a double
  5. } CLLocationCoordinate2D;
  6.  
  7. @property (readonly) CLLocationDistance altitude; //meters. A negative value means "below sea level"
  8.  
  9.  
  10. @property (readonly) CLLocationAccuracy horizontalAccuracy; //in meters
  11. @property (readonly) CLLocationAccuracy verticalAccuracy; //in meters
  12. kCLLocationAccuracyBestForNavigation;
  13. kCLLocationAccuracyBest;
  14. kCLLocationAccuracyKilometers;
  15. kCLLocationAccuracyThreeKilometers;
  16.  
  17. @property (readonly) CLLocationSpeed speed; // in meters/second
  18. @property (readonly) CLLocationDirection course; // in degrees, O is north, clockwise
  19.  
  20. @property (readonly) NSDate *timestamp;
  21.  
  22. - (CLLocationDistance) distanceFromLocation:(CLLocation *) otherLocation;
  23.  
  24. // How do you get a CLLocation?
  25. // from a CLLocationManager
  26.  
  27. //CLLocationManager: General appoach to using it: (4 steps)
  28. //1. Check to see if the hardware youare on/user supports the kind of location updating you want
  29. //2. Create a CLLocation instance and set the delegate to receive updates
  30. //3. Configure the manager according to what kind of location updating you want
  31. //4. Start the manager monitoring for location changes
  32.  
  33. // Kind of location monitoring
  34. // Accuracy-based continual updates
  35. // Updates only when "Significant" changes in location occur
  36. // Region-based updates.
  37. // Heading monitoring
  38.  
  39. // Check to see what your hardware can do
  40.  
  41. + (BOOL) locationServiceszEnabled; // has the user enabled the location monitoring in settings?
  42. + (BOOL) headingAvailable; // can this hardware provide heading info (compass)?
  43. + (BOOL) significantLocationChangeMonitoringAvailable; // only if device has cellular?
  44. + (BOOL) regionMonitoringAvailable; // only certain iOS4 devices
  45. + (BOOL) regionMonitoringEnabled; // by the user Settings;
  46.  
  47.  
  48.  
  49. // When your application first tries to use location monitoring, user will be asked if it's okay to do so.
  50. // You can provide a string which describes your app's purpose in using the location services.
  51. @property (copy) NSString *purpose;
  52. // If the user denies you, the appropriate method above will return NO
  53.  
  54.  
  55. @property CLLocationAccuracy desiredAccuracy; // always set this as low as possible
  56.  
  57. @property CLLocationDistance distanceFilter; // Only changes in location of at least this distance will fire a location update to you
  58.  
  59. // Starting and stopping the monitoring
  60. - (void) startUpdatingLocation;
  61. - (void) stopUpdatingLocation;
  62. // Be sure to turn off when your application is not going to consume the changes!
  63.  
  64. - (void) locationManager:(CLLocationManager *) manager
  65. didUpdateToLocation:(CLLocation *) newLocation
  66. fromLocation:(CLLocation *) oldLocation;
  67.  
  68. // Heading monitoring
  69.  
  70. @property CLLocationDegrees headingFilter;
  71. @property CLHeadingOrientation headingOrientation;
  72.  
  73. - (void) startUpdatingHeading;
  74. - (void) stopUpdatingHeading;
  75.  
  76. // get notified via CLLocationManager's delegate
  77. - (void) locationManager:(CLLocationManager *)manager
  78. didUpdating:(CLHeading *)newHeading;
  79.  
  80.  
  81. // CLHeading
  82. @property (readonly) CLLocationDirection magneticHeading;
  83. @property (readonly) CLLocationDirection trueHeading;
  84.  
  85. @property (readonly) CLLocationDirection headingAccuracy;
  86. @property (readonly) NSDate *timestamp;
  87.  
  88. // Heading calibration user-interface
  89.  
  90. - (BOOL) locationManagerShouldDisplayHeadingCalibration:(CLLocationManager *)manager;
  91. - (void) dismissHeadingCalibrationDisplay;
  92.  
  93. // Error reporting to the delegate
  94. - (void) locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error;
  95. //Not always a fatal thing, so pay attention to this delegate method:
  96. kCLErrorLocationUnknown // likely temporary, keep waiting (for a while at least)
  97. kCLErrorDenied // user refused to allow your application to receive updates
  98. kCLErrorHeadingFailure //too much local magnetic interference keep waiting
  99.  
  100.  
  101. // Significant location change monitoring in CLLocationManager
  102. // "Significant" is not strictly defined. Think vehicles, not walking. Likely uses cell towers
  103. - (void) startMonitoringSignificantLocationChanges;
  104. - (void) stopMonitoringSignificantLocationChanges;
  105.  
  106. // Get notified via the CLLocationManager's delegte
  107. // same as for accuracy-based updating if your application is running
  108. // But this works even if your application is not running! You will get launched and your application delegate will receive message
  109.  
  110. application:didFinishLaunchingWithOptions: // with an options dictionary that will contain
  111. UIApplicationLaunchOptionsLocationKey // Create a CLLocationManager (if you don't have one) then get the latest location via
  112. @property (readonly) CLLocation *location;
  113.  
  114. // Region-based location monitoring in CLLocationManager
  115. - (void) startMonitoringForRegion:(CLRegion *) desiredAccuracy:(CLLocationAccuracy);
  116. - (void) stopMonitoringForRegion:(CLRegion *);
  117.  
  118. // Get notified via the CLLocationManager's delegate
  119. - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region;
  120. - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region;
  121.  
  122. - (void)locationManager:(CLLocationManager *)manager
  123. monitoringDidFailForRegion:(CLRegion *)region
  124. withError:(NSError *)error;
  125.  
  126. // Works even if your application is not running
  127. // In exactly the same way as "significant location change" monitoring
  128. // The set of monitored regions persists across application termination/launch
  129.  
  130. @property (readonly) NSSet *monitoredRegions; // Property on CLLocationManager
  131.  
  132. // CLRegion s are tracked by name
  133. @property (readonly) CLLocationDistance maximumRegionMonitoringDistance;
  134.  
  135. // Displays an array of objects which implement MKAnnotation
  136. @property (readonly) NSArray *annotations; // contains id <MKAnnotation> objects
  137.  
  138. // MKAnnotation protocol
  139. @protocol MKAnnotation <NSObject>
  140. @property (readonly) CLLocationCoordinate2D coordinate;
  141.  
  142. @optional
  143. @property (readonly) NSString *title;
  144. @property (readonly) NSString *subtitle;
  145. @end
  146.  
  147. typedef {
  148. CLLocationDegrees latitude;
  149. CLLocationDegrees longtitude;
  150. } CLLocationCoordinate2D;
  151.  
  152. // Note that the annotations property is read only
  153. @property (readonly) NSArray *annotations // contains id <MKAnnotation> objets
  154. // MUST add/remove annotations explicitly
  155.  
  156. - (void)addAnnotation:(id <MKAnnotation>)annotation;
  157. - (void)addAnnotations:(NSArray *)annotations;
  158. - (void)removeAnnotation:(id <MKAnnotation>)annotation;
  159. - (void)removeAnnotations:(NSArray *)annotations;
  160.  
  161. // When you toudh on an annotation, the following delegate is called
  162.  
  163. - (void)mapView:(MKMapView *)sender didSelectAnnotationView:(MKAnnotationView *)aView;
  164. // This is a great place to set up the MKAnnotationView's callout accessory views lazily
  165. // For example, you migh want to wait until this method is called to download an image to show
  166.  
  167.  
  168. // How are MKAnnotationViews Created & associated w/annotations?
  169. // Very similar to UITableViewCells in a UITableView
  170. // Implement the following MKMapViewDelegate method (if not implemented, returns a pin view)
  171.  
  172. - (MKAnnotationView *)mapView:(MKMapView *)sender viewForAnnotation:(id <MKAnnotation>)annotation
  173. {
  174. MKAnnotationView *aView = [sender dequeueReusableAnnotionViewWithIdentifier:IDENT];
  175. if (!aView){
  176. aView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:IDENT];
  177.  
  178. // set canShowCallOut to YES and build aView's callout accessory views here
  179. }
  180. aView.annotation = annotation; // yes, this happens twice if no dequeue
  181. // maybe load up accessory views here (if not too expensive)
  182. // or reset them and wait until mapView:didSelectAnnotationView: to load actual data
  183.  
  184. return aView;
  185. }
  186.  
  187.  
  188. // MKAnnotationView interesting properties (all nonatomic, strong if a pointer)
  189. @property id <MKAnnotation> annotation; //the annotation, treat as if readonly
  190. @property UIImage *image; // instead of the pin, for example
  191. @property UIView *leftCalloutAccessoryView; // maybe a UIImageView
  192. @property UIView *rightCalloutAccessoryView; // maybe a disclosure UIButton
  193. @property BOOL enabled; // NO means it ignores touch events, no delegate method, no callout
  194. @property CGPoint centerOffset; // where the "head of the pin" is relative to the image
  195. @proprtty BOOL dragable; // only works if the annotation implements setCoordinate:
  196.  
  197. // if you set one of thecallout accessory views to a UIControl
  198. // e.g. aView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDisclosure];
  199.  
  200. // the following MKMapViewDelegate method will get called when the accessory view is touched...
  201.  
  202. - (void)mapView:(MKMapView *)sender annotationView:(MKAnnotationVIew *)aView calloutAccessoryControlTapped:(UIControl *)control;
  203.  
  204.  
  205. // Using didSelectAnnotationView: to load up callout accessories
  206. // example... downloaded thumbnail image in leftCalloutAccessoryView
  207. // Creat the UIImageView and assign it to leftCalloutAccessoryView in mapView:viewForAnnotation:
  208. // Reset the UIImageView's image to nil there as well
  209.  
  210. // then load the image on demand in mapView:didSelectAnnotationView ...
  211.  
  212. - (void)mapView:(MKMapVIew *)sender didSelectAnnotationView:(MKAnnotationView *)aView
  213. {
  214. if ([aView.leftCalloutAccessoryView isKindOfClass:[UIImageView class]]) {
  215. UIImageView *imageView = (UIImageVIew *)aView.leftCalloutAccessoryView;
  216. imageView.image = ...; // if you do this in a GCD queue, be careful, views are reused!
  217. }
  218. }
  219.  
  220.  
  221. // Configure the map view's display type
  222. @property MKMapType mapType;
  223. MKMapTypeStandrd, MKMapTypeSatelite, MKMapTypeHybird;
  224.  
  225. // show the user's current location
  226. @property BOOL showUserLocation;
  227. @property (readonly) BOOL isUserLocationVisible;
  228. @property (readonly) MKUserLocation *userLocation;
  229. MKUserLocation is an object which conforms to MKAnnotation which holds the users location
  230.  
  231. // Restricting the user's interaction with the map
  232.  
  233. @property BOOL zoomEnabled;
  234. @property BOOL scrollEnabled;
  235.  
  236. // Controlling the region the map displaying
  237. @property MKCoordinateRegion region;
  238. typedef struct {
  239. CLLocationCoordinate2D center;
  240. MKCoordinateSpan span;
  241. } MKCoordinateRegion;
  242. typedef struct {
  243. CLLocationDegrees latitudeDelta;
  244. CLLocationDegrees longtitudeDelta;
  245. }
  246.  
  247. - (void)setRegion:(MKCoordinateRegion)region animated:(BOOL)animated; //animate
  248.  
  249. // Can also set the center point only
  250. @property CLLocationCoordinate2D centerCoordinate;
  251. - (void)setCenterCoordinate:(CLLocationCoordinate2D)center animated:(BOOL)animated;
  252.  
  253. // Map loading notifications
  254. // remenber that the maps are downloaded from Google earth
  255.  
  256. - (void)mapViewWillStartLoadingMap:(MKMapView *)sender;
  257. - (void)mapViewDidFinishLoadingMap:(MKMapView *)sender;
  258. - (void)maoViewDidFailLoadingMap:(MKMapView *)sender withError:(NSError *)error;
  259.  
  260. // Lots of C functions to convert points, regions, rects, etc
  261. // see documentation, e.g. MKMapRectContainsPoint, MKMapPointForCoordinate, etc
  262.  
  263.  
  264. // Overlays: Mechanism is similar to annotations (uses MKOverlayView instead of MKAnnotationView)
  265.  
  266. - (void)addOverlay:(id <MKOverlay>)overlay;
  267. - (void)removeOverlay:(id <MKOverlay>) overlay;
  268.  
  269. // MKOverlay protocol
  270. // Protocol which includes MKAnnotation plus...
  271. @property (readonly)MKMapRect boundingMapRect;
  272. - (BOOL)intersectsMapRect:(MKMapRect)mapRect; // optional, uses boundingMapRect otherwise
  273.  
  274. // Overlays are associated with MKOverlayView s via delegate
  275. // just like annotations are associated with MKAnnotationViews...
  276. - (MKOverlayView *)mapView:(MKMapView *)sender viewForOverlay:(id <MKOverlay>)overlay;
  277. // MKOverlayView subclasses must be able to draw the overlay
  278. - (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context;
  279.  
  280. // this is not quite like drawRect: (because you'll notice that you are provided the context)
  281. // But you will still use CoreGraphics to draw (this method must be thead-safe, by the way).
  282. // Also notice that the rectangle to draw is in map coordinates, not view coordinates
  283.  
  284. // Converting to/from map point/rects from/to view coordinates
  285.  
  286. - (MKMapPoint)mapPointForPoint:(CGPoint)point;
  287. - (MKMapRect)mapRectForRect:(CGRect)rect;
  288. - (CGPont)pointForMapPoint:(MKMapPoint)mapPoint;
  289. - (CGRect)rectForMapRect:(MKMapRect)mapRect;
Add Comment
Please, Sign In to add comment