我创建了一些包含一些链接的地图(点击时)使用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/
任何人都可以帮助我吗?