How to increase the number of clicks on an icon in Google Maps

We are trying to increase the clickable area of ​​the marker on google map. The reason why we want to do is that clicking on the icon sometimes skips the anchor point. We are not reducing the icon size

We assume that one of the properties of the GIcon objects is what we need to change, and tried to change the iconAnchor and infoWindowAnchor property for the GIcon, but that doesn't seem to work.

Anyone point us in the right direction?

+1


a source to share


4 answers


Finally, we reduced the size of the image. We didn't notice that the recommended graphic size was 19x19



-2


a source


I know this has been around for a while, but I had the same problem, say your icon is 51 pixels wide and 32 pixels high:

var baseIcon = new GIcon(G_DEFAULT_ICON);
baseIcon.imageMap = [0,0 , 51,0, 51,32 , 0,32];

      



Basically you just enter the x, y coordinates

+2


a source


If you have different icons, it is recommended to create a dynamic image imageMap:

function getImgSize(imgSrc) {
   var newImg = new Image();
   newImg.src = imgSrc;
   var height = newImg.height;
   var width = newImg.width;
   return [height,width];
}

var icon = new GIcon(G_DEFAULT_ICON,iconUrl);
var iconSize = getImgSize(iconUrl);
icon.iconSize = new GSize(iconSize[1], iconSize[0]); // set icon size
icon.imageMap = [0,0, icon.iconSize.width,0, icon.iconSize.width,icon.iconSize.height,0,icon.iconSize.height]; // set click area
icon.shadowSize = new GSize(0, 0); // disable shadow

      

+2


a source


Link: http://code.google.com/apis/maps/documentation/reference.html#GIcon

iconAnchor and infoWindowAnchor set where in the image is the actual point on the map and the info window, respectively.

If you want to enlarge the area with clicks, you can do something with the non-IE imageMap property (I've never tried it). However, I think it is best to define a custom GIcon that uses a larger image (padded with transparent space). Unfortunately this is quite a bit of a hack - maybe someone else knows a better way.

0


a source







All Articles