2011-03-21 31 views
0

顯示一個HTML元素我知道如何放置標誌物和所有屬性似乎還好吧步驟接近精確

var marker = new google.maps.Marker({ 
     position : latlng, 
     map: map, 
     icon: icon, 
     shadow: icon_shadow, 
     title : name 
    }); 
google.maps.event.addListener(marker, 'mouseover', function() { 
    jQuery('#info').fadeIn(); 
    }); 

我如何定位信息框,以便它靠近針尖? 網站的地方,我看到這在行動似乎都使用api v2。

+0

大概可以使用jQuery的偏移量並得到頂部和左側,並利用這些作爲參考。 – kobe 2011-03-21 05:56:21

+0

@siri,我如何獲得標記的頂部/左側偏移量? – Moak 2011-03-21 05:59:45

回答

0

假設你有你的谷歌地圖作爲地圖變種,和你的標記命名標記

emptyoverlay = new google.maps.OverlayView(); 
emptyoverlay.draw = function() {}; 
emptyoverlay.setMap(map); 
google.maps.event.addListener(marker,'mouseover',function(){ 
     //Getting the x/y positions 
     var absPos = emptyoverlay.getProjection().fromLatLngToContainerPixel(this.getPosition()); 
     absPos.x += 10; // Now we have it we can shift around 
     absPos.y += -10; // Where the box shows up 
     console.log(absPos); 
     //jQuery magic starts here 
     jQuery('#message').show().html('anything you want').css({left: absPos.x, top: absPos.y}); 
}); 
google.maps.event.addListener(marker,'mouseout',function(){ 
     jQuery('#message').hide(); 
});