Sorry, you need to enable JavaScript to visit this website.

Map initialization

Map initialization

The Maps SDK for Android allows you to initialize the map with a setup configuration. For this purpose, use the MapFragment.newInstance() method or MapView constructor with MapProperties. The MapProperties object allows you to set initial map values of the map.

Initializing the map with bounding box

Programmatically:

val amsterdamTopLeft = LatLng(52.499782, 4.749553)
val amsterdamBottomRight = LatLng(52.246161, 5.031764)
val boundingBox = BoundingBox(amsterdamTopLeft, amsterdamBottomRight)
val focusArea: CameraFocusArea = CameraFocusArea.Builder(boundingBox)
    .pitch(5.0)
    .bearing(MapConstants.ORIENTATION_NORTH.toDouble())
    .build()
val apiKeys = mapOf(ApiKeyType.MAPS_API_KEY to BuildConfig.MAPS_API_KEY)
val mapProperties = MapProperties.Builder()
    .cameraFocusArea(focusArea)
    .keys(apiKeys)
    .build()
mapFragment = MapFragment.newInstance(mapProperties)

 

From XML:

<com.tomtom.online.sdk.map.MapView
    android:id="@+id/map_view"
    android:name="com.tomtom.online.sdk.map.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:cameraFocusAreaTopLeftLatitude="52.499782"
    app:cameraFocusAreaTopLeftLongitude="4.749553"
    app:cameraFocusAreaBottomRightLatitude="52.246161"
    app:cameraFocusAreaBottomRightLongitude="5.031764"
    app:cameraFocusAreaPitch="5.0"
    app:cameraFocusAreaBearing="0.0" />
Centering the map with starting point

Programmatically:

val tomtomOfficeLodz = LatLng(51.759434, 19.449011)
val cameraPosition = CameraPosition.builder()
    .focusPosition(tomtomOfficeLodz)
    .zoom(MapConstants.DEFAULT_ZOOM_LEVEL)
    .pitch(5.0)
    .bearing(MapConstants.ORIENTATION_NORTH.toDouble())
    .build()
val apiKeys = mapOf(ApiKeyType.MAPS_API_KEY to BuildConfig.MAPS_API_KEY)
val mapProperties = MapProperties.Builder()
    .cameraPosition(cameraPosition)
    .keys(apiKeys)
    .build()
mapFragment = MapFragment.newInstance(mapProperties)

 

From XML:

<fragment
    android:id="@+id/map_fragment"
    android:name="com.tomtom.online.sdk.map.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:cameraPositionLatitude="52.499782"
    app:cameraPositionLongitude="4.749553"
    app:cameraPositionZoom="14.0"
    app:cameraPositionPitch="5.0"
    app:cameraPositionBearing="0.0" />
image

Map initialized on Lodz Office of TomTom with 15 zoom level

image

Map initialized on Amsterdam area