我創建了一些包含一些鏈接的地圖(點擊時)使用jquery更改地圖位置。試圖在動態地圖中創建多個Google地圖標記
我試圖爲每個位置實現一個標記,但是要讓標記顯示在除默認設置之外的其他任何地圖位置上。
我試圖爲每個緯度和長時間值設置一個標記。我試圖使用下面的代碼,但我得到的錯誤:TypeError:map.setPosition不是螢火蟲控制檯中的函數。
我的代碼如下:
HTML:
<a id="link-aberdeen" href="javascript:void(0)" class="button1">Munich</a>
<a id="link-glasgow" href="javascript:void(0)" class="button2">Oxford</a>
<a id="link-glasgow" href="javascript:void(0)" class="button3">Glasgow</a>
<div id="map-canvas"></div>
CSS:
#map-canvas { background: #eaeaea none repeat scroll 0 0; height: 300px; width: 100%; }
JAVASCRIPT:
function initialize() {
map = new google.maps.Map(document.getElementById('map-canvas'), {
center: new google.maps.LatLng(48.1293954,12.556663), //Setting Initial Position
zoom: 10
});
var marker = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(48.1293954,12.556663),
center: new google.maps.LatLng(48.1293954,12.556663),
zoom: 10
});
}
function newLocation(newLat,newLng) {
map.setCenter({
lat : newLat,
lng : newLng
});
map.setPosition({
lat : newLat,
lng : newLng
});
}
google.maps.event.addDomListener(window, 'load', initialize);
$(document).ready(function() {
$(".button1").on('click', function() {
newLocation(48.1293954,12.556663);
});
$(".button2").on('click', function() {
newLocation(51.7163950,-1.2196100);
});
$(".button3").on('click', function() {
newLocation(55.8610240,-4.2614560);
});
});
我也有一個小提琴我一直在測試請參閱https://jsfiddle.net/xxfairydragonxx/7j31df1v/
任何人都可以幫助我嗎?