google maps marker LatLng to screen point fromLatLngToContainerPixel
function MyOverlay(map) { this.setMap(map); } MyOverlay.prototype = new google.maps.OverlayView(); MyOverlay.prototype.onAdd = function() {} MyOverlay.prototype.onRemove = function() { } MyOverlay.prototype.draw = function() { } //////////////////////////////////////
var overlay = new MyOverlay(map); google.maps.event.addListener(marker, 'click', function(e,a,b,c) { console.log("++++++++++++++console.log(marker)++++++++++++++++++") var latlng=marker.getPosition(); var pp = overlay.getProjection().fromLatLngToContainerPixel(latlng); console.log(pp); });
调用overlay.getProjection().fromLatLngToContainerPixel函数将经纬度转换成像素点pp。注意,pp的像素值是参照地图最左上角的那个点计算出来的
转载:http://hi.baidu.com/%B9%C2%B7%E7%D3%D6%C6%F0/blog/item/4b835116a6ca425cf3de32b3.html
中文手册 : https://developers.google.com/maps/documentation/javascript/overlays?hl=zh-CN#CustomOverlays