Cross Platform
Android
iOS
 

Change Map Modes

This recipe shows how to change the type of map being displayed in an MKMapView to either Road, Satellite or Hybrid.

Recipe

To change the mode of a MKMapView:

  1. Start with an existing MKMapView or review the Displaying a Location recipe.
  2. Change the map type in code using one of these statements:
mapView.MapType = MKMapType.Standard; // the default, road map
mapView.MapType = MKMapType.Satellite;
mapView.MapType = MKMapType.Hybrid;

  1. To add a segment control to allow the user to switch between modes, add the following code:
int typesWidth=260, typesHeight=30, distanceFromBottom=60;
mapTypes = new UISegmentedControl(new RectangleF((View.Bounds.Width-typesWidth)/2, View.Bounds.Height-distanceFromBottom, typesWidth, typesHeight));
mapTypes.InsertSegment("Road", 0, false);
mapTypes.InsertSegment("Satellite", 1, false);
mapTypes.InsertSegment("Hybrid", 2, false);
mapTypes.SelectedSegment = 0; // Road is the default
mapTypes.AutoresizingMask = UIViewAutoresizing.FlexibleTopMargin;
mapTypes.ValueChanged += (s, e) => {
    switch(mapTypes.SelectedSegment) {
    case 0:
        mapView.MapType = MKMapType.Standard;
        break;
    case 1:
        mapView.MapType = MKMapType.Satellite;
        break;
    case 2:
        mapView.MapType = MKMapType.Hybrid;
        break;
    }
};

Additional Information

When adding controls on top of a MKMapView, be sure not to obscure the Google logo. It is part of Apple’s Terms of Service that the logo be visible, and your app may be rejected if you have hidden it.