MapView

@IBDesignable
@objc(HereMapView)
@MainActor
open class MapView : UIView, MapViewBase

A view that displays a map. Note: Before using this class, SDKNativeEngine must be already initialized.

  • Callback to be called on retrieval of screenshot.

    Note

    In case of any error passed result is null.

    Declaration

    Swift

    public typealias TakeScreenshotCallback = (UIImage?) -> Void
  • This class represents a pinned UIView, that means an UIView at a fixed location on the map.

    The pinned view will automatically be repositioned on the screen as the map moves. There is more performance overhead involved in positioning an view as compared to a map marker, so for use cases which only require static images, markers should be used.

    See more

    Declaration

    Swift

    public class ViewPin
  • The MapCamera to control the angle of view for the map

    Declaration

    Swift

    @MainActor
    public var camera: MapCamera { get }
  • The gestures control object for setting up the capture of gestures.

    Declaration

    Swift

    @MainActor
    public var gestures: Gestures { get }
  • Declaration

    Swift

    @MainActor
    public var mapScene: MapScene { get }
  • Declaration

    Swift

    @MainActor
    public var mapContext: MapContext { get }
  • Declaration

    Swift

    @MainActor
    public var hereMap: HereMap { get }
  • Maximum render frame rate in frames per second. Setting to 0 disables automatic rendering for this view. Setting negative values has no effect. The default value is 60 frames per second.

    Declaration

    Swift

    @MainActor
    public var frameRate: Int32 { get set }
  • Returns the viewport size in physical pixels.

    Declaration

    Swift

    @MainActor
    public var viewportSize: Size2D { get }
  • The code of the desired primary map display language. If not set or if the desired language is not supported, then the language of the displayed region is used, which is the default behaviour. Applies to all instances of MapView. When changed, triggers redraw of any visible MapView.

    Declaration

    Swift

    @MainActor
    public static var primaryLanguage: LanguageCode? { get set }
  • The code of the desired secondary map display language. If the desired language is not supported, then the language of the displayed region is used. If not set, no secondary map language will be used which is the default behaviour. Applies to all instances of MapView. When changed, triggers redraw of any visible MapView. Note: This feature is in beta state and thus there can be bugs and unexpected behavior.

    Declaration

    Swift

    @MainActor
    public static var secondaryLanguage: LanguageCode? { get set }
  • The shadow quality for all instances of MapView. The quality controls the size of the shadow maps and the cascade count. The default shadow quality is {@code ShadowQuality.medium}. MapViews can request to render shadows by feature. Enabling shadows has a performance impact and should be considered only for devices with sufficient performance. Note: This feature is in beta state and thus there can be bugs and unexpected behavior.

    Declaration

    Swift

    @MainActor
    public static var shadowQuality: ShadowQuality { get set }
  • Pauses rendering of this instance of map view.

    Normally the application doesn’t need to call this method since the required handling of foreground/background switch is done from inside the HERESDK. However, if this needs to be called for some special reasons on application side, the application must call this method inapplicationWillResignActive(_:) of the application delegate or sceneWillResignActive(_:) of the scene delegate. Otherwise, it may result in rendering glitches as the renderer is prohibited from issuing rendering commands when being in background.

    Declaration

    Swift

    @MainActor
    public func pause()
  • Resumes rendering of this instance of map view.

    Normally the application doesn’t need to call this method since the required handling of foreground/background switch is done from inside the HERESDK. However, if this needs to be called for some special reasons on application side, the application must call this method in applicationDidBecomeActive(_:) of the application delegate or sceneDidBecomeActive(_:) of the scene delegate.

    Declaration

    Swift

    @MainActor
    public func resume()
  • Undocumented

    Declaration

    Swift

    @MainActor
    public convenience init()
  • Undocumented

    Declaration

    Swift

    @MainActor
    override public convenience init(frame: CGRect)
  • Initializes and returns a newly allocated view object

    Declaration

    Swift

    @MainActor
    public convenience init(options: MapViewOptions)

    Parameters

    options

    Customization of view for example its map projection

  • Initializes and returns a newly allocated view object with the specified frame rectangle.

    Declaration

    Swift

    @MainActor
    public convenience init(frame: CGRect, options: MapViewOptions)

    Parameters

    frame

    The frame rectangle for the view, measured in points.

    options

    Customization of view for example its map projection

  • Initializes and returns a newly allocated view object with the specified frame rectangle and sdk engine.

    Declaration

    Swift

    @MainActor
    public convenience init(frame: CGRect, withSdkEngine sdkEngine: SDKNativeEngine, options: MapViewOptions)

    Parameters

    frame

    The frame rectangle for the view, measured in points.

    withSdkEngine

    object used previously to initialize whole sdk

    options

    Optional customization of view for example its map projection

  • Undocumented

    Declaration

    Swift

    @MainActor
    public convenience init(frame: CGRect, withSdkEngine sdkEngine: SDKNativeEngine)
  • Initializes and returns a newly allocated view object with specified frame rectangle, sdk engine and options.

    Declaration

    Swift

    @MainActor
    public init(frame: CGRect, withSdkEngine sdkEngine: SDKNativeEngine, withOptions options: MapViewOptions?)

    Parameters

    frame

    The frame rectangle for the view, measured in points.

    withSdkEngine

    Object that was previously used to initialize whole sdk.

    withOptions

    Optional customization of view for example its map projection.

  • Undocumented

    Declaration

    Swift

    @MainActor
    public required init?(coder aDecoder: NSCoder)
  • Indicates whether this instance is valid. It will be made invalid when the corresponding SDKNativeEngine is destroyed.

    Declaration

    Swift

    @MainActor
    public var isValid: Bool { get }
  • Converts geographical coordinates to view coordinates (in pixels).

    If specified, altitude of the input coordinates is interpreted as altitude above sea level. If not specified, the input coordinates are interpreted as being on ground elevation. The above distinction is only relevant when 3D terrain feature is enabled.

    The resulting view coordinates might be outside of current viewport, i.e. result might contain values less than zero or greater than view’s dimensions.

    If the render surface is not attached, it will return nil.

    Declaration

    Swift

    @MainActor
    public func geoToViewCoordinates(geoCoordinates: GeoCoordinates) -> Point2D?

    Parameters

    geoCoordinates

    Geographical coordinates to convert.

    Return Value

    The view coordinates of the specified geographical point or nil if there is no render surface attached.

  • Converts view coordinates to geographical coordinates.

    An optional altitude component of the resulting geographical coordinate is not set.

    If the view coordinates specify a point above a horizon, then the result is geographical coordinates of the point on a horizon below the specified view coordinates.

    The fog effect is ignored for the calculation, meaning that for the view point within the area covered by the fog, the result is geographical coordinates that would be displayed at the specified point if the fog effect was not applied.

    If the render surface is not attached, it will return nil.

    Declaration

    Swift

    @MainActor
    public func viewToGeoCoordinates(viewCoordinates: Point2D) -> GeoCoordinates?

    Parameters

    viewCoordinates

    Point inside the view to convert.

    Return Value

    The geographical coordinates under specified view point or nil if there is no render surface attached.

  • Returns all map content located inside the specified pick area. Content to be picked is specified by a pick content filter. The pick area is defined by a rectangle in map view coordinates in pixels, relative to the map view’s origin at (0, 0) which indicates the top-left corner of the map view.

    Declaration

    Swift

    @MainActor
    public func pick(filter: MapScene.MapPickFilter?, inside viewArea: Rectangle2D, completion callback: @escaping (MapPickResult?) -> Void)

    Parameters

    filter

    Filter for the map content to be picked. When a filter is not set all of the pickable content will be picked.

    viewArea

    The rectangular pixel area of the view inside which map content will be picked. View area is relative to the map view’s origin at (0, 0) at the top-left corner of the map view.

    callback

    Callback to call with the result. This will be called on a main thread when pick operation completes.

  • Asynchronously retrieves a screenshot of current map view. Note that this does not work when the map view is currently not visible, for example, when an application is running in background - even if MapView.pause() was not called.

    Declaration

    Swift

    @MainActor
    public func takeScreenshot(callback: @escaping TakeScreenshotCallback)

    Parameters

    callback

    Completion handler called when the screenshot is completed.

  • Adds a MapViewLifecycleDelegate to this map view. Adding the same object multiple times has no effect.

    Declaration

    Swift

    @MainActor
    public func addLifecycleDelegate(_ lifecycleListener: MapViewLifecycleDelegate)

    Parameters

    lifecycleListener

    An object to be notified of lifecycle events.

  • Removes a MapViewLifecycleDelegate from this map view. Trying to remove an object that was not added or was removed before has no effect.

    Declaration

    Swift

    @MainActor
    public func removeLifecycleDelegate(_ lifecycleListener: MapViewLifecycleDelegate)

    Parameters

    lifecycleListener

    An object to stop being notified of lifecycle events.

  • Reinitializes the map renderer. Does nothing if isValid is true or SDKNativeEngine.sharedInstance is nil.

    This can be used after MapView gets invalidated as a result of destroying the shared SDKNativeEngine and setting a new shared SDKNativeEngine.

    After this call finishes successfully, isValid becomes true.

    Map state is not preserved. The caller must load a scene, set camera, re-add all the delegates and all the map items, etc.

    Any previously stored instances of MapView.camera, MapView.mapScene, MapView.mapContext, MapView.gestures and MapView.hereMap remain invalid.

    Declaration

    Swift

    @MainActor
    public func reinit()
  • Sets the position of the HERE logo watermark within the map view.

    By default, the watermark is aligned to the bottom-right corner of the view: Anchor2D(1.0, 1.0) and Point2D(-watermarkSize.width / 2, -watermarkSize.height / 2). It is recommended to change the default position only if necessary to avoid overlapping UI elements. The watermark should always be fully visible within the view. The anchor point on the watermark is its center (width/2, height/2), around which it will be placed in the map view. For map views smaller than 250 dip in both width and height, the watermark will not be shown.

    Declaration

    Swift

    @MainActor
    public func setWatermarkLocation(anchor: Anchor2D, offset: Point2D)

    Parameters

    anchor

    Anchor point in normalized view coordinates [0, 1]. Map view’s origin at (0, 0) indicates a top-left corner of the map view. Out of boundary anchor point values will be clamped to the [0, 1] range.

    offset

    A horizontal and vertical offset (expressed in positive/negative pixel coordinates) that allows shifting the watermark from the anchor point position in one or the other direction. For the quadrant of values expressing visible part of the map view negative offset shifts the watermark to the direction of the origin, positive - away from it. For example, the offset of (-10, 5) will shift the watermark 10px to the left and 5px to the bottom. If specified offset will result in watermark being completely or partially out-of-view the offset will be adjusted internally so that watermark is fully visible. Offset is not being scaled when the map view size changes.

  • The pixel scale factor used by this MapView. It is used to support screen resolution and size independence. This value is a derivative of the device’s screen pixel density and is a direct analog of the native scale factor for the physical screen.

    It can be used to translate between physical pixels and points according to formula: points = pixels / pixel_scale.

    Pixel scale is 0.0 if the map view is not initialized.

    In cases where the MapView moves in between screens (e.g. from main screen to a CarPlay screen), the most up-to-date pixel scale value can be obtained after a render target gets attached to the view. To get notified when a render target gets attached to the MapView, see MapViewLifecycleDelegate.onAttach.

    Declaration

    Swift

    @MainActor
    public var pixelScale: Double { get }
  • Provides the size of the watermark in physical pixels.

    Declaration

    Swift

    @MainActor
    public var watermarkSize: Size2D { get }
  • Pins a UIView to the MapView and returns a proxy object that can be used to control the pinning. Trying to pin a view that was already pinned or a view that has a super view has no effect and returns nil.

    The altitude component of the coordinates, if set, is interpreted as above sea level. When not set, the coordinates are interpreted as at ground level.

    Please note, a pinned UIView will be confined to the bounds of MapView by default. If this is not desired, setting MapView‘s property clipsToBounds to false will allow pinned views to exceed MapView’s bounds.

    Declaration

    Swift

    @MainActor
    public func pinView(_ view: UIView, to coordinates: GeoCoordinates) -> ViewPin?

    Parameters

    view

    UIView object to pin.

    coordinates

    GeoCoordinates to pin the view at.

    Return Value

    The ViewPin proxy object, or nil if view was not pinned.

  • Removes a ViewPin from the MapView by specifying the corresponding UIView. Trying to unpin a view that was not pinned or was unpinned before has no effect.

    Declaration

    Swift

    @MainActor
    public func unpinView(_ view: UIView)

    Parameters

    view

    The UIView corresponding to the ViewPin to remove.

  • Gets a copy of the array of currently added view pins.

    Declaration

    Swift

    @MainActor
    public var viewPins: [MapView.ViewPin] { get }
  • Handles low memory situation.

    This method should be called from a view controller, when it receives a memory warning (UIViewController.didReceiveMemoryWarning())

    Declaration

    Swift

    @MainActor
    public func handleLowMemory()