[英]link outside google maps to center map on marker
我有一個帶有多個標記的Google地圖。 在地圖外部,有地圖上顯示的標記列表。 我希望能夠從此列出的地址中建立鏈接,當我單擊它們時,將地圖放在相應標記的中心(不刪除所有其他標記)。
這是在Google Maps v3中添加標記使其居中時創建鏈接的示例:
function addMarker(myMap, myAddress, myLat, myLng) {
// Create Google Maps LatLng from position
var myLatLng = new google.maps.LatLng(myLat, myLng);
// Create the marker
var myMarker = new google.maps.Marker({
map: myMap
position: myLatLng
});
// Create a new anchor, bind click, and append to the container
$("<a></a>")
.attr("href", "#")
.html(myAddress)
.click(function() {
myMap.setCenter(myLatLng);
})
.appendTo(".myLinkContainer");
}
創建標記時最好這樣做,這樣就不必維護對LatLng
對象的引用,該引用定義了窗口級對象中的位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.