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||CLLocationCoordinate2D||The map coordinate that will represent the center of the viewport.||nil|
|altitude||CLLocationDistance||The altitude (measured in meters) above the map at which the camera should be situated.||nil|
|pitch||CGFloat||The viewing angle of the camera, measured in degrees||0|
|heading||CLLocationDistance||The camera’s heading, measured in degrees clockwise from true north.||nil|
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( lookingAtCenter:centerCoordinate, altitude: 500, pitch: 15, heading: 180) self.mapView.camera = camera
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:
mapView.setCamera( camera, withDuration: 5, animationTimingFunction: CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut))