2015-05-15 89 views
-2

在Google地圖中,我需要移動位於底部中心的Google徽標。 我怎樣才能讓它位於Botton左側。如何將Google地圖徽標移動到地圖的左下角

我想我需要jQuery來做到這一點,但無法弄清楚。

<div style="margin-left: 5px; margin-right: 5px; margin-bottom: 17px; z-index: 1000000; position: absolute; bottom: 0px; left: 921px;"> 
    <a style="position: static; overflow: visible; float: none; display: inline;" target="_blank" href="http://maps.google.com/maps?ll=53.648789,-8.514405&z=6&t=m&hl=en-GB&gl=US&mapclient=apiv3" title="Click to see this area on Google Maps"> 
     <div style="width: 52px; height: 20px; cursor: pointer;"> 
      <img style="position: absolute; left: 0px; top: 0px; width: 52px; height: 20px; -moz-user-select: none; border: 0px none; padding: 0px; margin: 0px;" src="https://maps.gstatic.com/mapfiles/api-3/images/google_dark.png" draggable="false"> 
     </div> 
    </a> 
</div> 

希望有人能幫助這個,請。

+2

我很確定他們的服務條款禁止你修改他們的標誌。 – j08691

+0

徽標覆蓋了一些標記,因此當有人試圖點擊標記時,它會打開一個新的Google地圖頁面而不是標記。 – user3297090

+0

他們不能只是平移地圖,以便徽標不覆蓋標記? –

回答

0

我用這個它,重新定位:

function GoogleLogoControl(controlDiv, map) { 
// Set CSS for the control div 
var controlUI = document.createElement('div'); 
controlUI.style.cursor = 'pointer'; 
controlUI.style.width = '52px'; 
controlUI.style.height = '20px'; 
controlUI.title = 'Click to see this area on Google Maps'; 
controlDiv.appendChild(controlUI); 

// Set CSS for the control image 
var controlImage = document.createElement('img'); 
controlImage.src = 'https://maps.gstatic.com/mapfiles/api-3/images/google_dark.png'; 
controlImage.style.width = '52px'; 
controlImage.style.height = '20px'; 
controlUI.appendChild(controlImage); 

google.maps.event.addDomListener(controlUI, 'click', function() { 
window.open('http://maps.google.com/maps?ll=53.648789,-8.327637&z=6&t=m&hl=en-GB&gl=US&mapclient=apiv3') 
}); 
} 

在功能初始化()我說:

// Add Google Logo to Bottom Right Corner as it was remove from Bottom Center using CSS 
var googlelogoControlDiv = document.createElement('div'); 
var googlelogoControl = new GoogleLogoControl(googlelogoControlDiv, map); 

googlelogoControlDiv.index = 1; 
map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(googlelogoControlDiv); 
1

我有一個類似的問題。我正在顯示附近的地方搜索表單,並將結果顯示在覆蓋地圖的半透明容器中。谷歌的標識被這個容器部分遮蓋了,爲了害怕違反了ToS,我想通過將其與容器的寬度抵消來使其可見。這是我做的:

我的目標是標題的元素,因爲它沒有任何類或任何東西。

$('[title="Click to see this area on Google Maps"]') 

重要的是要注意,除非我等待地圖完成加載,否則找不到元素。我已經在使用「tilesloaded」事件,所以我寫了一個名爲moveGoogleLogo()的函數,該函數在該事件被觸發時執行。

google.maps.event.addListenerOnce(map, 'tilesloaded', function(){ 

    // Move Google logo 
    moveGoogleLogo(); 

}); 


function moveGoogleLogo(){ 
    var container = $('#my-overlay-container') 
    $('[title="Click to see this area on Google Maps"]') 
    .closest('div').css('left', container.outerWidth()+'px'); 
} 

我注意到,元件本身被包裹在一個div,所以我用最接近()來獲取該div,然後加入我的容器的寬度爲左值。

這對我很有用!我希望這可以幫助別人。我意識到,如果他們在更高版本中更改標題,代碼將不得不更新,但不管。對我來說,這是一個比重新創建元素更好的解決方案。

UPDATE:

我的解決方案上面沒有工作,因爲我想要的方式,作爲地圖改變,標誌將重新定位。我最終做的是用.clone()克隆元素並隱藏原始元素。這似乎完成了工作。

相關問題