2013-04-24 49 views
0

我有谷歌地圖API的小問題。谷歌地圖API錨鏈接獲取位置

我成功嵌入google map v.3在此頁面後(https://developers.google.com/maps/documentation/javascript/examples/)。

現在我想在同一頁面放置一些鏈接,當我點擊一個鏈接時,請確定地圖中的位置。並顯示我的自定義地圖別針圖標。

ex。
...

<a href="link to get this place's location">Blah Blah City Convention Center</a> 
<a href="link to get this place's location2">Blah Blah Shopping Mall</a> 


如果有人知道官方頁面介紹了這樣或一些好的教程網站,請讓我知道。

我做了jsfiddle頁面開始。隨意修改:)

http://jsfiddle.net/nori2tae/NrYqA/

謝謝。

+0

你真的想要點擊一個超鏈接? 1)你想添加標記來映射? 2)你想在某些標記上顯示/打開信息窗口? 3)兩者? – 2013-04-24 05:53:03

+0

@ K.P。我想做3)兩者。當我點擊超鏈接時,我希望地圖移動到所需的位置和標記。要做到這一點,我的猜測是做一些事情,如把緯度和經度的位置給href?恩。 'a href =「google.map.latLng(123.45,67.890)」' – norixxx 2013-04-24 06:20:47

回答

0

當您將標記添加到地圖並將時間添加到每個標記(將事件添加到此標記時)時,請使用您的地圖,標記和超級鏈接的標識調用以下方法。

function attachEvents(map, myMarker, linkID) { 
     var markerRelDivObj = document.getElementById(linkID); 
     if (markerRelDivObj) { 
      markerRelDivObj.onmouseover = function() { 
       if (!map.getBounds().contains(myMarker.getPosition())) { 
        map.panTo(myMarker.getPosition()); 
       } 
       google.maps.event.trigger(myMarker, 'mouseover'); 
      }; 

      markerRelDivObj.onmouseout = function() { 
        google.maps.event.trigger(myMarker, 'mouseout'); 
      }; 
     } 
    } 
0

這裏的東西我沒有創造這使地圖移動和縮放兩個鏈接。

You can <a href="#" onclick="oMap.setCenter(new google.maps.LatLng(20, 14.2));oMap.setZoom(2);"> zoom out to see the global perspective</a> or <a href="#" onclick="oMap.setCenter(new google.maps.LatLng(54, -4));oMap.setZoom(6);"> see the UK here</a>

這假定您的腳本塊已經設置了一個名爲oMap的對象。