The mapView object is capable of displaying complex maps, but it also has muchmore functionality than that.It is set to communicate with your device GPS and therefore transfer liveinformation and live data to your application. Let's demonstrate this in this application.Go to the XIB and open the Assistant Editor, hold the Ctrl key, make sure thatyou have the header file selected.

Hold the Ctrl key and drag and create an outlet which we are going to call mapView.Make sure to import the MapKit framework.Go back to the Standard Editor and add the MapViewDelegate.What the delegate does is it allows you to receive method calls from the objectyou set delegation on, in this case the mapView.

In this movie, we want to define a map region based on the user current location.So first, let's synthesize the mapView properly.Set the mapView delegate to a class, and because we want to access the userlocation, we have to define the ShowUserLocation property as YES.The method used to capture the user location is the following: mapView didUpdateUserLocation.

When the mapView receives the update from the device, it will call this methodand parse the coordinate.So let's create a CLLocationCoordinate2D object in which we can store the userLocation.Next, let's create a region which will be defined by calling the methodMKCoordinateRegionWithDistance, and this method takes three parameters.

The first one is the coordinate, the second one is going to be the spanDistancefor the region along the latitude and longitude.Note that for this method we are parsing meters and not degrees.One meter represents about 3.3 feet, and now that the region is created, let'sjust set the region for the map to it, okay. Now let's run this.Note that for this movie, we are using the device. If you were to run thismovie on your simulator, the user location need not be where you currently arebut a default value.

So again to recap, to define a region, you could use hard coded data as well as live data.

Resume Transcript Auto-Scroll

Author

Released

8/3/2012

This course shows iOS developers how to add location awareness and maps to Apple iPhone and iPad applications. Discover how to show customers and clients where you're located and share directions with them.

Author Véronique Brossier covers the basic purpose of the Core Location and MapKit frameworks and how to integrate their services with your existing applications. Véronique shows how to center a map on a location, add annotations, create overlays, and zoom and navigate around maps. The course also covers how to leverage live location data such as course and speed and modify it when necessary.