Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
A ground overlay is an image fixed on a map.
Bitmap bitmap = BitmapFactory.decodeStream(getAssets().open("images/avocado.jpg"));
String fileName = "maomao.jpg";
String path = "/data/data/com.huawei.hms.maps.demo/avocado.jpg";
BitmapDescriptor descriptorFromAsset = BitmapDescriptorFactory.fromAsset("images/avocado.jpg");
BitmapDescriptor descriptorFromBitmap = BitmapDescriptorFactory.fromBitmap(bitmap);
BitmapDescriptor descriptorFromFile = BitmapDescriptorFactory.fromFile(fileName);
BitmapDescriptor descriptorFromPath = BitmapDescriptorFactory.fromPath(path);
BitmapDescriptor descriptorFromResource = BitmapDescriptorFactory.fromResource(R.drawable.makalong);val bitmap = BitmapFactory.decodeStream(assets.open("images/avocado.jpg"))
val fileName = "maomao.jpg"
val path = "/data/data/com.huawei.hms.maps.demo/avocado.jpg"
val descriptorFromAsset = BitmapDescriptorFactory.fromAsset("images/avocado.jpg")
val descriptorFromBitmap = BitmapDescriptorFactory.fromBitmap(bitmap)
val descriptorFromFile = BitmapDescriptorFactory.fromFile(fileName)
val descriptorFromPath = BitmapDescriptorFactory.fromPath(path)
val descriptorFromResource = BitmapDescriptorFactory.fromResource(R.drawable.makalong)String path = "/data/data/com.huawei.hms.maps.demo/avocado.jpg";
BitmapDescriptor descriptor = BitmapDescriptorFactory.fromPath(path);
GroundOverlayOptions options =
new GroundOverlayOptions().position(new LatLng(48.893478, 2.334595), 60, 30).image(descriptor);var path = "/data/data/com.huawei.hms.maps.demo/avocado.jpg"; var descriptor = BitmapDescriptorFactory.fromPath(path); val options = GroundOverlayOptions().position(LatLng(48.893478, 2.334595), 60f, 30f).image(descriptor)
private GroundOverlay mGroundOverlay; // Add a ground overlay on the map. mGroundOverlay = hMap.addGroundOverlay(options);
private var mGroundOverlay: GroundOverlay? = null // Add a ground overlay on the map. mGroundOverlay = hMap.addGroundOverlay(options)
if (null != mGroundOverlay) {
// Set a ground overlay.
mGroundOverlay.setImage(BitmapDescriptorFactory.fromResource(R.drawable.makalong));
}
if (null != mGroundOverlay) {
// Remove the ground overlay.
mGroundOverlay.remove();
}if (null != mGroundOverlay) {
// Set a ground overlay.
mGroundOverlay?.setImage(BitmapDescriptorFactory.fromResource(R.drawable.makalong))
}
if (null != mGroundOverlay) {
// Remove the ground overlay.
mGroundOverlay?.remove()
}position(LatLng location, float width) and position(LatLng location, float width, float height) cannot be used together with positionFromBounds(LatLngBounds bounds). Otherwise, IllegalStateException will be thrown.
This method sets the position of a ground overlay based on the longitude and latitude and image width (in meters). The image height is automatically calculated and adjusted based on the aspect ratio and width of the image.
This method sets the position of a ground overlay based on the longitude and latitude, image width (in meters), and image height (in meters). The image will be zoomed to adapt to the specified resolutions and may be deformed.
This method specifies a LatLngBounds object that provides two LatLng objects (southwest corner and northeast corner) to form a rectangle area. It will set the position of a ground overlay based on the rectangular area.
Ground Overlay Tap Event
You can use HuaweiMap.OnGroundOverlayClickListener to listen for ground overlay tap events. To set a listener on a map, call the setOnGroundOverlayClickListener(HuaweiMap.OnGroundOverlayClickListener) method of the HuaweiMap object. When a user taps a ground overlay, onGroundOverlayClick(GroundOverlay) calls the ground overlay.
hMap.setOnGroundOverlayClickListener(new HuaweiMap.OnGroundOverlayClickListener() {
@Override
public void onGroundOverlayClick(GroundOverlay groundOverlay) {
Toast.makeText(getApplicationContext(), "GroundOverlay is clicked.", Toast.LENGTH_LONG).show();
}
});hMap.setOnGroundOverlayClickListener { Toast.makeText(applicationContext, "GroundOverlay is clicked.", Toast.LENGTH_LONG).show() }