Document Maps SDK for Android Guides Controls and Gestures Map Events

Map Events

Method Interaction refers to the programmatic control of the map view. The Map SDK provides a variety of interface methods for interacting with the map, such as changing the visible region (i.e., the map center), adjusting the zoom level, and restricting the map's display bounds.

The core methods for method Interaction rely on two methods provided by the AMap class. The difference lies in the CameraUpdate object parameter used; different parameters produce different visual effects. The following sections detail three common interaction methods. For other methods, refer to the official reference manual.

This document also describes how to change the default map display area. Note that changing the default display area does not use the two core methods below.

Method with animated camera movement:

// Provided by the AMap class, includes a movement animation
animateCamera(CameraUpdate cameraupdate, long duration, AMap.CancelableCallback cancelablecallback);

Method without animated camera movement:

// Provided by the AMap class, moves directly without animation
moveCamera(CameraUpdate cameraupdate);

Change the Map Center

To change the map center point, construct a CameraUpdate parameter as follows:

// Parameters: center point coordinates of the target area, zoom level, tilt angle (0°–45°, 0 is perpendicular to the map), bearing angle (0°–360°, 0 is north)
CameraUpdate mCameraUpdate = CameraUpdateFactory.newCameraPosition(
    new CameraPosition(new LatLng(39.977290, 116.337000), 18, 30, 0));

Change the Zoom Level

To change the map zoom level, construct a CameraUpdate parameter as follows:

// Set the desired zoom level
CameraUpdate mCameraUpdate = CameraUpdateFactory.zoomTo(17);

The map zoom level ranges from 3 to 19, with 17 levels total. A higher number displays more detailed map information.

Name

Description

Usage

ZoomTo

Zooms the map to a specified zoom level.

AMap.moveCamera(CameraUpdateFactory.zoomTo(17))

ZoomIn

Zooms the map in by one level from the current zoom level.

AMap.moveCamera(CameraUpdateFactory.zoomIn())

Restrict the Map Display Bounds

Starting from Map SDK V4.1.0, you can set the map display bounds. The device screen will only show the specified map area. For example, you can restrict the map to display only the Beijing city area.

Note: If map display bounds are restricted, the map rotation gesture will be disabled.

Example usage:

LatLng southwestLatLng = new LatLng(33.789925, 104.838326);
LatLng northeastLatLng = new LatLng(38.740688, 114.647472);
LatLngBounds latLngBounds = new LatLngBounds(southwestLatLng, northeastLatLng);
aMap.setMapStatusLimits(latLngBounds);

Change the Default Map Display Area

By default, the map displays the Beijing area. To change the default display area, use the overloaded MapView constructor:

MapView mapView = new MapView(this, mapOptions);

Code example:

// Define the coordinates for the center of Beijing (example)
LatLng centerBJPoint = new LatLng(39.904989, 116.405285);

// Define a configuration object for the AMap instance
AMapOptions mapOptions = new AMapOptions();

// Set the initial camera position
// CameraPosition parameters:
//   1st: Center point coordinates of the target location on the screen.
//   2nd: Zoom level of the target visible region.
//   3rd: Tilt angle of the target visible region, in degrees.
//   4th: Bearing of the visible region, in degrees, measured clockwise from true north (0° to 360°).
mapOptions.camera(new CameraPosition(centerBJPoint, 10f, 0, 0));

// Create a MapView object, passing the mapOptions configuration
MapView mapView = new MapView(this, mapOptions);

// Call the onCreate method to set the MapView LayoutParams
mapView.onCreate(savedInstanceState);