How to Change the Map Type in Your iOS App - dummies

How to Change the Map Type in Your iOS App

By Neal Goldstein, Dave Wilson

MapKit supports three Map types — standard, satellite, and hybrid. Depending on the functionality you need for your iOS app, you may want to change your map type. The Map type is a Map View property and is represented as an enumerated type, which you may have cleverly made the segment numbers in the segmented control correspond to

enum { MKMapTypeStandard, MKMapTypeSatellite, MKMapTypeHybrid};

Add the code in bold to the mapType: method stub that was created when you added the action in Interface Builder. The code ensures that, when the user selects a new value in the segmented control, it will change the Map type based on the selection.

- (IBAction)mapType:(id)sender {
self.mapView.mapType =
((UISegmentedControl *)sender).selectedSegmentIndex;

When the user selects a segment in the segmented control, a value-changed event is generated. This is the event (Value Changed) that you specified when you created the action while setting up the MapController in the MainStoryboard_iPad.

The segmented control has a selectedSegmentIndex property, which contains the value of the selected segment.

You may have to do a cast here because the sender is of type id — a pointer to an object — which doesn’t have a selectedSegmentIndex property.