メインコンテンツまでスキップ

Display a simple map view

This example demonstrates how to create a basic map using the MapboxMaps class from the Mapbox Maps SDK for iOS. The BasicMapExample class inherits from UIViewController and conforms to the ExampleProtocol.

In the viewDidLoad method, a CameraOptions object is created with specified center coordinates, zoom level, bearing, and pitch. These options are used to initialize MapInitOptions which are then used to create the MapboxMaps instance with the given camera options. The map view is added as a subview to the current view, with a visible scale bar ornament. Finally, in the viewDidAppear method, a finishing function is called for internal testing purposes.

iOS Examples App Available

This example code is part of the Maps SDK for iOS Examples App, a working iOS project available on Github. iOS developers are encouraged to run the examples app locally to interact with this example in an emulator and explore other features of the Maps SDK.

See our Run the Maps SDK for iOS Examples App tutorial for step-by-step instructions.

BasicMapExample.swift
import UIKit
import MapboxMaps

final class ViewController: UIViewController {
private var mapView: MapView!

override func viewDidLoad() {
super.viewDidLoad()

let cameraOptions = CameraOptions(
center: CLLocationCoordinate2D(latitude: 41.879, longitude: -87.635),
zoom: 16,
bearing: 12,
pitch: 60)
let options = MapInitOptions(cameraOptions: cameraOptions)

mapView = MapView(frame: view.bounds, mapInitOptions: options)

mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
mapView.ornaments.options.scaleBar.visibility = .visible

view.addSubview(mapView)
}


}
このexampleは役に立ちましたか?