Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
The following table describes the camera attributes.
| Attribute | Description |
|---|---|
| target | Longitude and latitude of the map center. |
| bearing | Angle of a map rotated from the north in the clockwise direction. |
| tilt | Angle of the camera from the nadir (directly facing the Earth), in degrees. |
| zoom | Zoom level near the center of the screen. |
Huawei maps are moved by simulating camera movement. You can control the visible region of a map by changing the camera's position. To change the camera's position, create different types of CameraUpdate objects using the CameraUpdateFactory class, and use these objects to move the camera.
- // Method 1: Increase the camera zoom level by 1 and retain other attribute settings.
- CameraUpdate cameraUpdate = CameraUpdateFactory.zoomIn();
-
- // Method 2: Decrease the camera zoom level by 1 and retain other attribute settings.
- CameraUpdate cameraUpdate1 = CameraUpdateFactory.zoomOut();
-
- // Method 3: Set the camera zoom level to a specified value and retain other attribute settings.
- float zoom = 8.0f;
- CameraUpdate cameraUpdate2 = CameraUpdateFactory.zoomTo(zoom);
-
- // Method 4: Increase or decrease the camera zoom level by a specified value.
- float amount = 2.0f;
- CameraUpdate cameraUpdate3 = CameraUpdateFactory.zoomBy(amount);
-
- // Method 5: Move the camera to the specified center point and increase or decrease the camera zoom level
- // by a specified value.
- Point point = new Point(31, 118);
- float amount = 2.0f;
- CameraUpdate cameraUpdate4 = CameraUpdateFactory.zoomBy(amount, point);
-
- // Method 6: Set the latitude and longitude of the camera and retain other attribute settings.
- LatLng latLng1 = new LatLng(31.5, 118.9);
- CameraUpdate cameraUpdate5 = CameraUpdateFactory.newLatLng(latLng1);
-
- // Method 7: Set the visible region and padding.
- int padding = 100;
- LatLng latLng1 = new LatLng(31.5, 118.9);
- LatLng latLng2 = new LatLng(32.5, 119.9);
- LatLngBounds latLngBounds = new LatLngBounds(latLng1, latLng2);
- CameraUpdate cameraUpdate6 = CameraUpdateFactory.newLatLngBounds(latLngBounds, padding);
-
- // Method 8: Set the center point and zoom level of the camera.
- float zoom = 0.0f;
- LatLng latLng2 = new LatLng(32.5, 119.9);
- CameraUpdate cameraUpdate7 = CameraUpdateFactory.newLatLngZoom(latLng2, zoom);
-
- // Method 9: Scroll the camera by specified number of pixels.
- float x = 100.0f;
- float y = 100.0f;
- CameraUpdate cameraUpdate8 = CameraUpdateFactory.scrollBy(x, y);
-
- // Method 10: Specify the camera position.
- // Set the tilt.
- float tilt = 2.2f;
- // Set the bearing.
- float bearing = 31.5f;
- CameraPosition cameraPosition = new CameraPosition(latLng1,zoom,tilt,bearing);
- CameraUpdate cameraUpdate9 = CameraUpdateFactory.newCameraPosition(cameraPosition);
- // Method 1: Increase the camera zoom level by 1 and retain other attribute settings.
- val cameraUpdate = CameraUpdateFactory.zoomIn()
-
- // Method 2: Decrease the camera zoom level by 1 and retain other attribute settings.
- val cameraUpdate1 = CameraUpdateFactory.zoomOut()
-
- // Method 3: Set the camera zoom level to a specified value and retain other attribute settings.
- val zoom = 8.0f
- val cameraUpdate2 = CameraUpdateFactory.zoomTo(zoom)
-
- // Method 4: Increase or decrease the camera zoom level by a specified value.
- val amount = 2.0f
- val cameraUpdate3 = CameraUpdateFactory.zoomBy(amount)
-
- // Method 5: Move the camera to the specified center point and increase or decrease the camera zoom level
- // by a specified value.
- val point = Point(31, 118)
- val amount = 2.0f
- val cameraUpdate4 = CameraUpdateFactory.zoomBy(amount, point)
-
- // Method 6: Set the latitude and longitude of the camera and retain other attribute settings.
- val latLng1 = LatLng(31.5, 118.9)
- val cameraUpdate5 = CameraUpdateFactory.newLatLng(latLng1)
-
- // Method 7: Set the visible region and padding.
- val padding = 100
- val latLng1 = LatLng(31.5, 118.9)
- val latLng2 = LatLng(32.5, 119.9)
- val latLngBounds = LatLngBounds(latLng1, latLng2)
- val cameraUpdate6 = CameraUpdateFactory.newLatLngBounds(latLngBounds, padding)
-
- // Method 8: Set the center point and zoom level of the camera.
- val zoom = 0.0f
- val latLng2 = LatLng(32.5, 119.9)
- val cameraUpdate7 = CameraUpdateFactory.newLatLngZoom(latLng2, zoom)
-
- // Method 9: Scroll the camera by specified number of pixels.
- val x = 100.0f
- val y = 100.0f
- val cameraUpdate8 = CameraUpdateFactory.scrollBy(x, y)
-
- // Method 10: Specify the camera position.
- // Set the tilt.
- val tilt = 2.2f
- // Set the bearing.
- val bearing = 31.5f
- val cameraPosition = CameraPosition(latLng1, zoom, tilt, bearing)
- val cameraUpdate9 = CameraUpdateFactory.newCameraPosition(cameraPosition)
You can move the map camera in animation or non-animation mode.
When moving the map camera in animation mode, you can set the animation duration and API to be called back when the animation stops. By default, the animation duration is 250 ms.
Camera movement in non-animation mode is transient.
- // Move the map camera in animation mode.
- hMap.animateCamera(cameraUpdate);
- // Move the map camera in animation mode, and set the API to be called back when the animation stops.
- hMap.animateCamera(cameraUpdate, cancelableCallback);
- // Move the map camera in animation mode, and set the animation duration and API to be called back when the animation stops.
- hMap.animateCamera(cameraUpdate, durationMs, cancelableCallback);
-
- // Move the map camera in non-animation mode.
- hMap.moveCamera(cameraUpdate);
- // Move the map camera in animation mode.
- hMap.animateCamera(cameraUpdate)
- // Move the map camera in animation mode, and set the API to be called back when the animation stops.
- hMap.animateCamera(cameraUpdate, cancelableCallback)
- // Move the map camera in animation mode, and set the animation duration and API to be called back when the animation stops.
- hMap.animateCamera(cameraUpdate, durationMs, cancelableCallback)
-
- // Move the map camera in non-animation mode.
- hMap.moveCamera(cameraUpdate)
- // Set the preferred minimum zoom level. The value ranges from 3 to 20.
- hMap.setMinZoomPreference(3);
- // Set the preferred maximum zoom level. The value ranges from 3 to 20.
- hMap.setMaxZoomPreference(14);
- // Reset the preferred maximum and minimum zoom levels.
- hMap.resetMinMaxZoomPreference();
- // Set the preferred minimum zoom level.
- hMap.setMinZoomPreference(3f)
- // Set the preferred maximum zoom level.
- hMap.setMaxZoomPreference(14f)
- // Reset the preferred maximum and minimum zoom levels.
- hMap.resetMinMaxZoomPreference()
Figure 1 and Figure 2 show the effect before and after the camera position is specified.
| Figure 1 Before specifying the camera position | Figure 2 After specifying the camera position |
The Map SDK allows you to set the map camera bounds. You can call the setLatLngBoundsForCameraTarget(LatLngBounds) API to specify a LatLngBounds object to constrain the camera target so it will not get out of the specified bounds when users scroll the map camera. If this parameter is set to null, the map camera bounds will be cleared.