Simple map view
A newer version of the Maps SDK is available
This page uses v6.4.1 of the Mapbox Maps SDK. A newer version of the SDK is available. Learn about the latest version, v11.9.0, in the Maps SDK documentation.
Other Mapbox template styles can be displayed by referencing any of the defined convenience methods on MGLStyle
.
Or view the Apply a style designed in Mapbox Studio example to learn how to display custom map style created in Mapbox Studio.
import Mapbox
@objc(SimpleMapViewExample_Swift)
class SimpleMapViewExample_Swift: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let mapView = MGLMapView(frame: view.bounds)
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
// Set the map’s center coordinate and zoom level.
mapView.setCenter(CLLocationCoordinate2D(latitude: 59.31, longitude: 18.06), zoomLevel: 9, animated: false)
view.addSubview(mapView)
}
}
#import "ViewController.h"
@import Mapbox;
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
MGLMapView *mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds];
mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
// Set the map’s center coordinate and zoom level.
[mapView setCenterCoordinate:CLLocationCoordinate2DMake(59.31, 18.06)
zoomLevel:9
animated:NO];
[self.view addSubview:mapView];
}
@end