3

I am using Google Map in an Android app.

Google Map API provides a setOnMarkerClickListener so that we can do what we want when user clicks on a marker.

    googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(Marker marker) {
            //Do my stuff here
        }
    });

However, my marker image is pretty large and I only want a small part of it to be clickable.

And it seems there is no method of Marker that returns its X Y position in its fragment.

So, is this actually feasible, assuming that I must use Google Map?

Sira Lam
  • 4,412
  • 24
  • 53
  • Please note that this is asked in an Android context. – Sira Lam Apr 25 '18 at 10:17
  • however you may do this by click listener of google map. google providing onclick listener for google map. – Hitesh Sarsava Apr 25 '18 at 10:23
  • @HiteshSarsava Do you mean OnMapClickListener? That returns a LatLng which is not applicable. User can zoom the map and the LatLng can differs largely, which has no relationship with the marker. – Sira Lam Apr 25 '18 at 10:26
  • 1
    Perhaps a somewhat complex solution would be to colocate a transparent marker (alpha = 0) that has a small icon and associate the two markers using the 'tag' property and process the small marker as if the large marker was clicked. – Andy Apr 26 '18 at 01:03
  • 3
    The feature request for clickable marker area exists since 2013 (33 stars at the moment): https://issuetracker.google.com/issues/35823783. However, it looks like Google didn't set high priority on this task. – xomena Apr 27 '18 at 17:03
  • I found a way to manually handle clicks for markers: https://stackoverflow.com/a/58140323/1499750 – jc12 Sep 27 '19 at 19:21

0 Answers0