We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
GuidesMap KitAndroidEnhanced SDKPoint Annotation

Point Annotation

You can add point annotations to a map to identify locations such as stores and buildings, and provide location details with information windows. This function allows you to:

  • Set the text and icon collision rule.
  • Set animations for the title and icon.
  • Add click events.

Adding a Point Annotation

Call the addPointAnnotation method of HuaweiMapEx to add a point annotation on the map.

The sample code is as follows:
Java
Kotlin
Collapse
Word wrap
Dark theme
Copy code
  1. private Title title = new Title();
  2. private PointAnnotationOptions pointAnnotationOptions;
  3. // Define the anchor point of an icon.
  4. pointAnnotationOptions = new PointAnnotationOptions().anchor(0.5f, 0.5f).position(new LatLng(47.893478, 2.334595)).zIndex(5);
  5. // Set the icon.
  6. pointAnnotationOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.avocado));
  7. // Set the collision mode. The default collision mode is FONT (text collision only).
  8. pointAnnotationOptions.isCollision(pointAnnotationOptions.ALL);
  9. // Set the maximum zoom level.
  10. pointAnnotationOptions.maxZoom(15);
  11. // Set the minimum zoom level.
  12. pointAnnotationOptions.minZoom(0);
  13. // Set the zoom level.
  14. pointAnnotationOptions.zoom(0.0f, 15.0f);
  15. // Set the overlapping relationship.
  16. pointAnnotationOptions.zIndex(1);
  17. // Set the collision priority. A larger value indicates a lower priority.
  18. pointAnnotationOptions.priority(3f);
  19. // Set the title.
  20. title.setContent("point");
  21. pointAnnotationOptions.title(title);
  22. // Set whether the point annotation is visible.
  23. pointAnnotationOptions.visible(true);
  24. // Add a point annotation.
  25. hMapEx.addPointAnnotation(pointAnnotationOptions);
Collapse
Word wrap
Dark theme
Copy code
  1. val title = Title()
  2. var pointAnnotationOptions: PointAnnotationOptions
  3. // Define the anchor point of an icon.
  4. pointAnnotationOptions = PointAnnotationOptions().anchor(0.5f, 0.5f).position(LatLng(47.893478, 2.334595)).zIndex(5)
  5. // Set the icon.
  6. pointAnnotationOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.avocado))
  7. // Set the collision mode. The default collision mode is FONT (text collision only).
  8. pointAnnotationOptions.isCollision(pointAnnotationOptions.ALL)
  9. // Set the maximum zoom level.
  10. pointAnnotationOptions.maxZoom(15f)
  11. // Set the minimum zoom level.
  12. pointAnnotationOptions.minZoom(0f)
  13. // Set the zoom level.
  14. pointAnnotationOptions.zoom(0.0f, 15.0f)
  15. // Set the overlapping relationship.
  16. pointAnnotationOptions.zIndex(1)
  17. // Set the collision priority. A larger value indicates a lower priority.
  18. pointAnnotationOptions.priority(3f)
  19. // Set the title.
  20. title.content = "point"
  21. pointAnnotationOptions.title(title)
  22. // Set whether the point annotation is visible.
  23. pointAnnotationOptions.visible(true)
  24. // Add a point annotation.
  25. hMapEx.addPointAnnotation(pointAnnotationOptions)

The figure below shows the point annotation collision effect.

Listening for Point Annotation Events

You can use HuaweiMapEx.OnPointAnnotationClickListener to listen for point annotation click events. To set a listener for point annotation click events, call the setOnPointAnnotationClickListener method of the HuaweiMapEx object.

The sample code is as follows:
Java
Kotlin
Collapse
Word wrap
Dark theme
Copy code
  1. // Add a listener for point annotation click events.
  2. hMapEx.setOnPointAnnotationClickListener(new HuaweiMapEx.OnPointAnnotationClickListener() {
  3. @Override
  4. public void onPointAnnotationClick(PointAnnotation pointAnnotation) {
  5. Toast.makeText(getApplicationContext(), "onPointAnnotationClick", Toast.LENGTH_SHORT).show();
  6. }
  7. });
Collapse
Word wrap
Dark theme
Copy code
  1. // Add a listener for point annotation click events.
  2. hMapEx.setOnPointAnnotationClickListener { Toast.makeText(applicationContext, "onPointAnnotationClick", Toast.LENGTH_SHORT).show() }

Setting Animations for a Point Annotation

You can set animations for the title and icon of a point annotation. For the title, you can set the font size animation (FontSizeAnimation). For the icon, you can set the transparency animation (AlphaAnimation) and scale animation (ScaleAnimation). To set animations, you can call the setTitleAnimation or setIconAnimation method of PointAnnotation, and then call the startTitleAnimation or startIconAnimation method to start the animation.

The sample code is as follows:
Java
Kotlin
Collapse
Word wrap
Dark theme
Copy code
  1. private FontSizeAnimation fontSizeAnimation;
  2. private PointAnnotation mPoint;
  3. // Create a font size animation.
  4. fontSizeAnimation = new FontSizeAnimation(10, 80);
  5. // Set the fill mode.
  6. fontSizeAnimation.setFillMode(1);
  7. // Set the repeat mode.
  8. fontSizeAnimation.setRepeatMode(1);
  9. // Set the number of repetitions.
  10. fontSizeAnimation.setRepeatCount(1);
  11. // Set the animation duration.
  12. fontSizeAnimation.setDuration(1000);
  13. // Add an animation listener.
  14. Animation.AnimationListener listener = new Animation.AnimationListener() {
  15. @Override
  16. public void onAnimationStart() {
  17. Toast.makeText(getApplicationContext(), "FontSizeAnimation start", Toast.LENGTH_SHORT).show();
  18. }
  19. @Override
  20. public void onAnimationEnd() {
  21. Toast.makeText(getApplicationContext(), "FontSizeAnimation end", Toast.LENGTH_SHORT).show();
  22. }
  23. };
  24. fontSizeAnimation.setAnimationListener(listener);
  25. // Set the title animation for a point annotation.
  26. mPoint.setTitleAnimation(fontSizeAnimation);
  27. // Enable the title animation.
  28. mPoint.startTitleAnimation();
Collapse
Word wrap
Dark theme
Copy code
  1. var fontSizeAnimation : FontSizeAnimation
  2. var mPoint : PointAnnotation
  3. // Create a font size animation.
  4. fontSizeAnimation = FontSizeAnimation(10f, 80f)
  5. // Set the fill mode.
  6. fontSizeAnimation.fillMode = 1
  7. // Set the repeat mode.
  8. fontSizeAnimation.repeatMode = 1
  9. // Set the number of repetitions.
  10. fontSizeAnimation.repeatCount = 1
  11. // Set the animation duration.
  12. fontSizeAnimation.duration = 1000
  13. // Add an animation listener.
  14. val listener: Animation.AnimationListener = object : Animation.AnimationListener {
  15. override fun onAnimationStart() {
  16. Toast.makeText(applicationContext, "FontSizeAnimation start", Toast.LENGTH_SHORT).show()
  17. }
  18. override fun onAnimationEnd() {
  19. Toast.makeText(applicationContext, "FontSizeAnimation end", Toast.LENGTH_SHORT).show()
  20. }
  21. }
  22. fontSizeAnimation.setAnimationListener(listener)
  23. // Set the title animation for a point annotation.
  24. mPoint.setTitleAnimation(fontSizeAnimation)
  25. // Enable the title animation.
  26. mPoint.startTitleAnimation()

The figure below shows the title animation of a point annotation.