Changing the Map Type

MapKit supports the three Map types you see on Google maps — standard, satellite, and hybrid.

The Map type is a Map View property and is represented as an enumerated type, which I have cleverly made the segment numbers in the segmented control correspond to:

enum {

MKMapTypeStandard,

MKMapTypeSatellite,

MKMapTypeHybrid

};

Add the code in bold in Listing 17-8 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.

Listing 17-8: Updating mapType:

- (IBAction)mapType:(id)sender {

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 in Step 4 in the “Setting up the MapController in the MainStoryboard” section, earlier in this chapter.

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

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

Notice that the text is white — pretty plain vanilla, if you know what I mean. To change the text to something more spring-like — a nice green, in other words — add the code in bold in Listing 17-9 to application:didFinish ...

Get iPad Application Development For Dummies, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.