Skip to main content

The camera

The camera is how the user views the map. It can be centered on a location, zoomed, tilted, rotated and moved. The camera can be set programmatically but also controlled through user interaction with gestures.

The camera is typically set using the TMGLMapCamera class which is made up of center, altitude, pitch and heading parameters.

AttributeTypeDescriptionDefault Setting
centerCLLocationCoordinate2DThe map coordinate that will represent the center of the viewport.nil
altitudeCLLocationDistanceThe altitude (measured in meters) above the map at which the camera should be situated.nil
pitchCGFloatThe viewing angle of the camera, measured in degrees0
headingCLLocationDistanceThe camera’s heading, measured in degrees clockwise from true north.nil

Setting the TMGLMapCamera

The code below sets the camera’s target/center to be a coordinate in New York City. Once the TMGLMapCamera is defined, the map is updated with the new position.

// Center the map camera over New York City.
let centerCoordinate = CLLocationCoordinate2D(
latitude: 40.7128, longitude: -74.0060)

let camera = TMGLMapCamera(
                                altitude: 500,
                                pitch: 15,
                                heading: 180) = camera

Animating the CameraPosition

In addition to setting the map’s camera position, you can also animate a “flight” for the new camera position information, gliding into it. An example of this is below:

                    withDuration: 5,
                    animationTimingFunction: CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut))
Last updated December 2, 2022.