get bounds of an icon/marker


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function getIconBounds(marker){
  2. var iconSize, iconAnchorPoint, iconAnchorPointOffset,
  3. iconBoundsPointSw, iconBoundsPointNe, iconBoundsLatLngSw,
  4. iconBoundsLatLngNe;
  5. iconSize=marker.getIcon().iconSize;
  6. iconAnchorPoint=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getLatLng(),
  7. map.getZoom());
  8. iconAnchorPointOffset=marker.getIcon().iconAnchor;
  9. iconBoundsPointSw=new GPoint(iconAnchorPoint.x-
  10. iconAnchorPointOffset.x, iconAnchorPoint.y-iconAnchorPointOffset.y
  11. +iconSize.height);
  12. iconBoundsPointNe=new GPoint(iconAnchorPoint.x-
  13. iconAnchorPointOffset.x+iconSize.width, iconAnchorPoint.y-
  14. iconAnchorPointOffset.y);
  15.  
  16. iconBoundsLatLngSw=map.getCurrentMapType().getProjection().fromPixelToLatLng(iconBoundsPointSw,
  17. map.getZoom());
  18.  
  19. iconBoundsLatLngNe=map.getCurrentMapType().getProjection().fromPixelToLatLng(iconBoundsPointNe,
  20. map.getZoom());
  21. return new GLatLngBounds(iconBoundsLatLngSw, iconBoundsLatLngNe);
  22.  
  23. }

URL: http://groups.google.com/group/Google-Maps-API/browse_thread/thread/effe106b5ee6d6cd/3dc16de627bfe1e0?lnk=gst&q=clustering

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.