-2

How to inflate a custom view inside a google map fragment?

To add images/points on map we can use Markers or GroundOverlay, but if we need a custom view (for example, a list or an image with buttons), both classes receive a BitmapDescriptor on their attributes .icon and .image, respectively, which turns a given layout into a plain image, losing its versatility, for example unable to add onClickListeners on buttons.

So is there a way to add a custom view inside google map fragment without it being transformed into an image?

E.Akio
  • 2,249
  • 3
  • 14
  • 27
  • what exactly you want to accomplish by adding this custom view ? – Vivek Mishra Jun 28 '21 at 12:50
  • @VivekMishra for now, add a layout with texts and interactions, initially onClicks – E.Akio Jun 28 '21 at 12:53
  • 1
    then, instead of adding it to google map can't you just overlay a view over the map using frame layout ? – Vivek Mishra Jun 28 '21 at 12:57
  • well, lets add that i want to add this view directly into a position - if i attach it over the map than it would be fixed and i would have to disable map interactions (such as dragging etc) – E.Akio Jun 28 '21 at 13:03
  • can a custom infowindow for a marker help you ? – Vivek Mishra Jun 28 '21 at 13:05
  • that's an approach i'm open to discuss – E.Akio Jun 28 '21 at 13:08
  • 1
    This link might help you https://developers.google.com/maps/documentation/android-sdk/infowindows – Vivek Mishra Jun 28 '21 at 13:10
  • @VivekMishra This part of documentation was important "Note: The info window that is drawn is not a live view...". There is no way to add multiple clicks on different items on a Marker/Ground/InfoWindow... that was the best answer for my question, therefore ill close this, ty for linking it – E.Akio Jun 28 '21 at 14:13
  • so what you want to accomplish can't be done ? – Vivek Mishra Jun 29 '21 at 13:15
  • I did found one answer https://stackoverflow.com/questions/14123243/google-maps-android-api-v2-interactive-infowindow-like-in-original-android-go/15040761 and one library https://github.com/Appolica/InteractiveInfoWindowAndroid that could lead into an answer. Yet one seems overcomplicated (not their fault) and other makes you dependent on a 3rd party. What i want is something in the middle, where you can create it and don't need to create so many behaviours. – E.Akio Jun 29 '21 at 13:26

1 Answers1

0

Documentation clearly states that views will be rendered into images which annul any changes previously given to the view. Therefore there is no way to create a custom view with different behaviours inside google map.

Note: The info window that is drawn is not a live view. The view is rendered as an image (using View.draw(Canvas)) at the time it is returned. This means that any subsequent changes to the view will not be reflected by the info window on the map. To update the info window later (for example, after an image has loaded), call showInfoWindow(). Furthermore, the info window will not respect any of the interactivity typical for a normal view such as touch or gesture events. However you can listen to a generic click event on the whole info window as described in the section below.

From documentation: link

E.Akio
  • 2,249
  • 3
  • 14
  • 27