Maps
MGLAccountManager
The MGLAccountManager
object provides a global way to set a API access token.
Declaration
Objective-C
@interface MGLAccountManager : NSObject
Swift
class MGLAccountManager : NSObject
MGLMapCamera
An MGLMapCamera
object represents a viewpoint from which the user observes some point on an MGLMapView
.
Declaration
Objective-C
@interface MGLMapCamera : NSObject <NSSecureCoding, NSCopying>
Swift
class MGLMapCamera : NSObject, NSSecureCoding, NSCopying
MGLMapView
An interactive, customizable map view with an interface similar to the one provided by Apple’s MapKit.
Using MGLMapView
, you can embed the map inside a view, allow users to manipulate it with standard gestures, animate the map between different viewpoints, and present information in the form of annotations and overlays.
The map view loads scalable vector tiles that conform to the Vector Tile Specification. It styles them with a style that conforms to the GL Style Specification. Such styles can be designed in MapTiler Customize and hosted on maptiler.com.
A collection of hosted styles is available through the MGLStyle
class. These basic styles use Streets or Satellite data sources, but you can specify a custom style that makes use of your own data.
MapTiler-hosted vector tiles and styles require an API access token, which you can obtain from the MapTiler account page. Access tokens associate requests to MapTiler’s vector tile and style APIs with your MapTiler account. They also deter other developers from using your styles without your permission.
Because MGLMapView
loads asynchronously, several delegate methods are available for receiving map-related updates. These methods can be used to ensure that certain operations have completed before taking any additional actions. Information on these methods is located in the MGLMapViewDelegate
protocol documentation.
Adding your own gesture recognizer to MGLMapView
will block the corresponding gesture recognizer built into MGLMapView
. To avoid conflicts, define which gesture takes precedence. For example, you can create your own UITapGestureRecognizer
that will be invoked only if the default MGLMapView
tap gesture fails:
let mapTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(myCustomFunction))
for recognizer in mapView.gestureRecognizers! where recognizer is UITapGestureRecognizer {
mapTapGestureRecognizer.require(toFail: recognizer)
}
mapView.addGestureRecognizer(mapTapGestureRecognizer)
Note
You are responsible for getting permission to use the map data and for ensuring that your use adheres to the relevant terms of use.
Declaration
Objective-C
@interface MGLMapView : UIView <MGLStylable>
Swift
class MGLMapView : UIView, MGLStylable
MGLUserTrackingMode
The mode used to track the user location on the map. Used with MGLMapView.userTrackingMode
.
Declaration
Objective-C
enum MGLUserTrackingMode {}
Swift
enum MGLUserTrackingMode : UInt
MGLMapViewDelegate
The MGLMapViewDelegate
protocol defines a set of optional methods that you can use to receive map-related update messages. Because many map operations require the MGLMapView
class to load data asynchronously, the map view calls these methods to notify your application when specific operations complete. The map view also uses these methods to request information about annotations displayed on the map, such as the styles and interaction modes to apply to individual annotations.
Declaration
Objective-C
@protocol MGLMapViewDelegate <NSObject>
Swift
protocol MGLMapViewDelegate : NSObjectProtocol
MGLMapSnapshot
An image generated by a snapshotter object.
Declaration
Objective-C
@interface MGLMapSnapshot : NSObject
Swift
class MGLMapSnapshot : NSObject
MGLMapSnapshotOptions
The options to use when creating images with the MGLMapSnapshotter
.
Declaration
Objective-C
@interface MGLMapSnapshotOptions : NSObject <NSCopying>
Swift
class MGLMapSnapshotOptions : NSObject, NSCopying
MGLMapSnapshotter
An MGLMapSnapshotter
generates static raster images of the map. Each snapshot image depicts a portion of a map defined by an MGLMapSnapshotOptions
object you provide. The snapshotter generates an MGLMapSnapshot
object asynchronously, calling MGLMapSnapshotterDelegate
methods if defined, then passing it into a completion handler once tiles and other resources needed for the snapshot are finished loading.
You can change the snapshotter’s options at any time and reuse the snapshotter for multiple distinct snapshots; however, the snapshotter can only generate one snapshot at a time. If you need to generate multiple snapshots concurrently, create multiple snapshotter objects.
For an interactive map, use the MGLMapView
class. Both MGLMapSnapshotter
and MGLMapView
are compatible with offline packs managed by the MGLOfflineStorage
class.
From a snapshot, you can obtain an image and convert geographic coordinates to the image’s coordinate space in order to superimpose markers and overlays. If you do not need offline map functionality, you can use the Snapshot
class in MapboxStatic.swift to generate static map images with overlays.
Example
let camera = MGLMapCamera(lookingAtCenter: CLLocationCoordinate2D(latitude: 37.7184, longitude: -122.4365), altitude: 100, pitch: 20, heading: 0)
let options = MGLMapSnapshotOptions(styleURL: MGLStyle.satelliteStreetsStyleURL, camera: camera, size: CGSize(width: 320, height: 480))
options.zoomLevel = 10
let snapshotter = MGLMapSnapshotter(options: options)
snapshotter.start { (snapshot, error) in
if let error = error {
fatalError(error.localizedDescription)
}
image = snapshot?.image
}
Declaration
Objective-C
@interface MGLMapSnapshotter : NSObject <MGLStylable>
Swift
class MGLMapSnapshotter : NSObject, MGLStylable
iOS SDK
Examples
SDK JS Reference
- Annotations
- Appendices
- NSExpression(MGLAdditions)
- NSValue(MGLAdditions)
- NSValue(MGLCircleStyleLayerAdditions)
- NSValue(MGLFillExtrusionStyleLayerAdditions)
- NSValue(MGLFillStyleLayerAdditions)
- NSValue(MGLHillshadeStyleLayerAdditions)
- NSValue(MGLLineStyleLayerAdditions)
- NSValue(MGLRasterStyleLayerAdditions)
- NSValue(MGLSymbolStyleLayerAdditions)
- MGLAccountManager
- MGLAnnotationImage
- MGLAnnotationView
- MGLAttributedExpression
- MGLAttributionInfo
- MGLBackgroundStyleLayer
- MGLCircleStyleLayer
- MGLClockDirectionFormatter
- MGLCompassButton
- MGLCompassDirectionFormatter
- MGLComputedShapeSource
- MGLCoordinateFormatter
- MGLDistanceFormatter
- MGLFillExtrusionStyleLayer
- MGLFillStyleLayer
- MGLForegroundStyleLayer
- MGLHeatmapStyleLayer
- MGLHillshadeStyleLayer
- MGLImageSource
- MGLLight
- MGLLineStyleLayer
- MGLLoggingConfiguration
- MGLMapCamera
- MGLMapSnapshot
- MGLMapSnapshotOptions
- MGLMapSnapshotOverlay
- MGLMapSnapshotter
- MGLMapView
- MGLMultiPoint
- MGLMultiPolygon
- MGLMultiPolyline
- MGLNetworkConfiguration
- MGLOfflinePack
- MGLOfflineStorage
- MGLPointAnnotation
- MGLPointCollection
- MGLPolygon
- MGLPolyline
- MGLRasterStyleLayer
- MGLRasterTileSource
- MGLShape
- MGLShapeCollection
- MGLShapeOfflineRegion
- MGLShapeSource
- MGLSource
- MGLStyle
- MGLStyleLayer
- MGLSymbolStyleLayer
- MGLTilePyramidOfflineRegion
- MGLTileSource
- MGLUserLocation
- MGLUserLocationAnnotationView
- MGLUserLocationAnnotationViewStyle
- MGLVectorStyleLayer
- MGLVectorTileSource
- MGLAnnotationVerticalAlignment
- MGLAnnotationViewDragState
- MGLAttributionInfoStyle
- MGLCirclePitchAlignment
- MGLCircleScaleAlignment
- MGLCircleTranslationAnchor
- MGLDEMEncoding
- MGLErrorCode
- MGLFillExtrusionTranslationAnchor
- MGLFillTranslationAnchor
- MGLHillshadeIlluminationAnchor
- MGLIconAnchor
- MGLIconPitchAlignment
- MGLIconRotationAlignment
- MGLIconTextFit
- MGLIconTranslationAnchor
- MGLLightAnchor
- MGLLineCap
- MGLLineJoin
- MGLLineTranslationAnchor
- MGLLoggingLevel
- MGLMapDebugMaskOptions
- MGLOfflinePackState
- MGLOrnamentPosition
- MGLOrnamentVisibility
- MGLRasterResamplingMode
- MGLResourceKind
- MGLSymbolPlacement
- MGLSymbolZOrder
- MGLTextAnchor
- MGLTextJustification
- MGLTextPitchAlignment
- MGLTextRotationAlignment
- MGLTextTransform
- MGLTextTranslationAnchor
- MGLTextWritingMode
- MGLTileCoordinateSystem
- MGLUserTrackingMode
- Formatters
- Geometry
- Location Updates
- Maps
- Offline Maps
- Other Categories
- Other Classes
- Other Constants
- Other Enumerations
- Other Functions
- Other Protocols
- Other Structures
- Other Type Definitions
- Primitive Shapes
- MGLAnnotation
- MGLCalloutView
- MGLCalloutViewDelegate
- MGLCluster
- MGLComputedShapeSourceDataSource
- MGLFeature
- MGLLocationManager
- MGLLocationManagerDelegate
- MGLMapSnapshotterDelegate
- MGLMapViewDelegate
- MGLOfflineRegion
- MGLOfflineStorageDelegate
- MGLOverlay
- MGLStylable
- MGLCoordinateBounds
- MGLCoordinateQuad
- MGLCoordinateSpan
- MGLOfflinePackProgress
- MGLSphericalPosition
- MGLTransition
- Style Content
- Style Layers
- Style Primitives
- Styling the Map
- MGLCoordinateBounds
- MGLCoordinateQuad
- MGLCoordinateSpan
- MGLOfflinePackProgress
- MGLSphericalPosition
- MGLTransition
- User Interaction
- Customizing Fonts
- Information for Style Authors
- Gesture Recognizers
- Info.plist Keys
- Migrating to Expressions
- Predicates and expressions
- Tile URL Templates
- Working with GeoJSON Data