Saturday, July 5, 2014

Using CoreLocation and MapKit

I have been going thru BNR iOS book. Here are few of examples I did step by step while going thru the chapters.

In https://github.com/technobuzz/WhereAreYou I used the CoreLocation and the MapKit. CoreLocation allows the device to figure out the geographical location.

In the view controller,  I used the CLLocationManager class which controls the geographical capabilities for the device. Note that I had to add the CoreLocation framework to the project, and add the following to the header file to use it


#import <CoreLocation/CoreLocation.h>

Moreover, added the CLLocationManagerDelegate to the view controller.

As well, in the view controller i used the MapKit. The MapKit allows you to show a Map on the device. This too required that I had to add the MapKit framework to the project, and add the following to the header file to use it:

#import <MapKit/MapKit.h>

For the MapKit library, I made use of MKMapView class. as well as the MKMapViewDelegate

In the MKMapView class, there is a method didUpdateUserLocation which tells us that the users location was updated.  In this method gets invoked within the view controller, I make it zoom in on the map as follows (with a 250x250 meter region):

CLLocationCoordinate2D loc = [userLocation coordinate];
MKCoordinateRegion region =
MKCoordinateRegionMakeWithDistance(loc,250,250);

In this example, a location on the map is indicated using MKAnnotation. I created a class that conforms to MKAnnotation.

Note: I also did their QuizApp.

No comments:

Post a Comment