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

Map centering

Map centering

Center the map in your mobile app either at the current coordinates or any other location at the zoom level of your choice. Alternatively you can define an area of the map which will be displayed to the user. In the latter case the zoom level will be adjusted automatically.

Sample use case 1: You want to display the maps for selected cities in specific zoom levels. Your users should be able to easily switch between different locations.

Sample use case 2: You want to display an area determined by a certain bounding box.

Use the following code snippets in your app to display maps either of different locations (in this case, the current location and the TomTom offices in Amsterdam and Berlin) or of a certain area.

The example shows how to center the map on Amsterdam with the zoom level set to 10:

_

tomtomMap.centerOn(
        Locations.AMSTERDAM_LOCATION.getLatitude(),
        Locations.AMSTERDAM_LOCATION.getLongitude(),
        DEFAULT_ZOOM_LEVEL,
        MapConstants.ORIENTATION_NORTH);
tomtomMap.centerOn(location.latitude,
    location.longitude,
    zoomLevel,
    bearing)

 

The following example shows how to center the map on the area containing Amsterdam-Haarlem and Amsterdam-Center locations. Applied parameters make the map South-up oriented with a camera pitch set to 45 degrees.

_

BoundingBox areaBox = new BoundingBox(topLeft, bottomRight);
CameraFocusArea cameraFocusArea = new CameraFocusArea.Builder(areaBox)
        .bearing(MapConstants.ORIENTATION_SOUTH)
        .pitch(45.0)
        .build();
tomtomMap.centerOn(cameraFocusArea, new AnimationDuration(1500, TimeUnit.MILLISECONDS));
val areaBox = BoundingBox(topLeft, bottomRight)
val cameraFocusArea = CameraFocusArea.Builder(areaBox)
    .apply {
        bearing(MapConstants.ORIENTATION_SOUTH.toDouble())
        pitch(45.0)
    }
    .build()
tomtomMap.centerOn(cameraFocusArea, AnimationDuration(1500, TimeUnit.MILLISECONDS))

 

image

Map centered on Amsterdam with 10 zoom level

image

Map centered on Berlin with 10 zoom level

image

South-up oriented map centered on an area including Amsterdam-Haarlem and Amsterdam Central. The camera pitch is set to 45 degrees.