JB GPS Location App

From CSclasswiki
Jump to: navigation, search

Core Location

Core Location is a framework that manages location.

CLLocation - Your Current Location

An object that represents a point and vector in the real world

@property CLLocationCoordinate2D coordinate;
 @property CLLocationDistance altitude;

@property CLLocationAccuracy horizontalAccuracy; /*The radius of uncertainty for the location, measured in meters. */
@property CLLocationAccuracy verticalAccuracy; /*The accuracy of the altitude value in meters.*/

@property CLLocationDirection course; /*The direction in which the device is traveling. Starts at 0 at due north, measured in degrees. */
@property CLLocationSpeed speed;

- (NSDate *)timeStamp; /*The time at which the location was measured*/
- (CLLocationDistance)distanceFromLocation:(CLLocation *)location

CLLocationManager - The Managing of the GPS

The CLLocationManager class defines the interface for configuring the delivery of location- and heading-related events to your application. You use an instance of this class to establish the parameters that determine when location and heading events should be delivered and to start and stop the actual delivery of those events. You can also use a location manager object to retrieve the most recent location and heading data.

How does it do it?

It determines your current location through a three-pronged attack:

  • GPS
  • Wifi
  • Cell network

The more accurate a location you request, the more power it drains from the battery.

Mapkit

Mapkit is an API to display maps, in a manner very similar to Google Maps. There is support for annotations (pins on the map).

MKMapView

  • Handles panning and zooming
  • Displays user location
@property MKCoordinateRegion region; 
@property CLLocationCoordinate2D centerCoordinate;
@property MKMapType mapType;
@property NSArray *annotations; 
@property MKUserLocation userLocation;
@property id <MKMapViewDelegate> delegate;

MKAnnotation

A @protocol that allows the addition of pins to a map.

Using custom MKAnnotationViews, these pins can display almost anything to the user (photos, videos, other forms of media.)


@property CLLocationCoordinate2D coordinate;
@property NSString *title; 
@property NSString *subtitle;

Map Demo

1. Create a new Window-Based project. Call it Map Demo. 2. Add the MapKit framework (Control + Click Frameworks folder -> Add -> Existing Frameworks) 3. Open MainWindow.xib. Add a MapView control to it. Compile and run. ... 3. Create a new view controller class (right click on Project -> Add -> New File -> UIViewController Subclass, make sure 'create XIB' is selected) and call it MapViewController. Add a text field, button and map view to it.

#import <UIKit/UIKit.h>
    #import <MapKit/MapKit.h>

    @interface MapViewController : UIViewController<MKMapViewDelegate> {
        IBOutlet UITextField *addressField;
        IBOutlet UIButton *goButton;
        IBOutlet MKMapView *mapView;
    }

    @end

4. Open MapViewController.xib Set its type to MapViewController and add a UITextField, UIButton and MKMapView to it.