2

I'm new to google maps or rather android programming. Nevertheless I just managed to set up a google map for an internet browser. I created several custom markers (markers with my own icon) which have a specific clickable area.

For google maps for internet browsers this down by

      var shape = {
      coords: [1, 1, 1, 20, 18, 20, 18, 1],
      type: 'poly'
    };
    for (var i = 0; i < beaches.length; i++) {
      var beach = beaches[i];
      var marker = new google.maps.Marker({
        position: {lat: beach[1], lng: beach[2]},
        map: map,
        icon: image,
        shape: shape,
        title: beach[0],
        zIndex: beach[3]
      });
    }

So you define a shape which will be your clickable area of the marker. This works.

Now I like to develop my google map application for an android device. I want the same marker icon as I used in google maps for browsers. Though this is not written in JavaScript like before but in Java and I've already done it. But I can't manage to find an option to create a clickable or rather a touchable area for my custom markers on android google maps! There is even a larg area around my custom icon and I can't change it.

So do you know an option how I can define the clickable/touchable area for google map markers for android? Or is it not possible because the thumb isn't accurate as a computer mouse?

Screenshot of my map with the problem

With kind regards, Taskmanager

Taskmanager
  • 439
  • 2
  • 7
  • 18

1 Answers1

0

You need to register OnInfoWindowClickListenerCallback. There is a method in GoogleMap for that:

map.setOnInfoWindowClickListener(new OnInfoWindowClickListener()
        {
            @Override
            public void onInfoWindowClick(Marker arg0) {
                //Handle your click here                
        }
        }); 

Update:

// Set a listener for marker click.    
mMap.setOnMarkerClickListener(this);

/** Called when the user clicks a marker. */
@Override
public boolean onMarkerClick(final Marker marker) {

    // Retrieve the data from the marker.
    Integer clickCount = (Integer) marker.getTag();

    // Check if a click count was set, then display the click count.
    if (clickCount != null) {
        clickCount = clickCount + 1;
        marker.setTag(clickCount);
        Toast.makeText(this,
                       marker.getTitle() +
                       " has been clicked " + clickCount + " times.",
                       Toast.LENGTH_SHORT).show();
    }

    // Return false to indicate that we have not consumed the event and that we wish
    // for the default behavior to occur (which is for the camera to move such that the
    // marker is centered and for the marker's info window to open, if it has one).
    return false;
}

Refer Markers for more details. Also make sure the image you are using for markers does not have padding within it.

Akshay
  • 6,029
  • 7
  • 40
  • 59
  • 1
    Thanks for your respond. I don't have any infowindow because I only need the markers itself. The markers are already clickable and I have a clicklistener for them which works as desired. The problem is that I can't reduce the size of the marker's clickable/touchable area like with the shape on the browser version. The clickable area is too big. [Please see my screenshot](https://i.stack.imgur.com/hIUKp.jpg) Rgds, Taskmanager – Taskmanager Jan 25 '18 at 15:15