Camera Positioning
MapLayr provides powerful camera control capabilities that allow you to programmatically navigate your map.
The moveCamera
function takes a CameraTarget
parameter and a boolean parameter as to whether the camera should animate to the target position.
Move the Camera to a Specific Location
In this case use the CameraTarget.Geographic
class.
mapView.moveCamera(
cameraTarget = CameraTarget.Geographic(
coordinates = GeographicCoordinate(52.8949, -1.8445),
headingDegrees = 45.0,
span = 100.0,
insets = 0.0,
tilt = Math.toRadians(45.0)
),
animated = true
)
Move the Camera to the User's Current Location
In this case use the CameraTarget.LocationId
class along with one of the GoogleLocationId.HighAccuracy
, GoogleLocationId.Balanced
or GoogleLocationId.Passive
classes (see User Location Marker). The camera will automatically move as the user's current location updates unless the user interacts with the map.
mapView.moveCamera(
cameraTarget = CameraTarget.LocationId(
locationId = GoogleLocationId.HighAccuracy,
span = 100.0
),
animated = true
)
Move the Camera to Display a Journey
In this case use the CameraTarget.Journey
class. The camera will automatically move to display the entire route as the route updates unless the user interacts with the map.
mapView.moveCamera(
cameraTarget = CameraTarget.Journey(
journey = journey,
tilt = Math.toRadians(30.0),
fallback = CameraTarget.Stationary
),
animated = true
)
An example can be found here: ExtendedSampleActivity.kt
Move the Camera to Display All Destinations
In this case use the CameraTarget.ResolvableDestinations
class. The camera will move so that all of the provided GeographicCoordinate
objects are displayed.
mapView.moveCamera(CameraTarget.ResolvableDestinations(
listOf(
GeographicCoordinate(52.8952, -1.8431),
GeographicCoordinate(52.8982, -1.8463),
GeographicCoordinate(52.8983, -1.8494),
GeographicCoordinate(52.8971, -1.8443),
GeographicCoordinate(52.8949, -1.8445)
),
headingDegrees = Math.toRadians(45.0),
insets = 0.0,
tilt = 0.0,
))
An example can be found here: ExtendedSampleActivity.kt