我正在尝试在WordPress functions.php中添加多个Google地图,但只显示最后一张地图。
如何显示多张地图? 是否可以创建一个短代码循环?
我试图替换var" map"使用$ arg或随机ID但没有成功。
with open(f,'r') as fh:
all = fh.read()
re.search('PIN(.*)END', all, re.DOTALL)
答案 0 :(得分:0)
这适用于单独的js文件(不在functions.php短代码中)
function initMap(id, lang, long) {
var map = new google.maps.Map(document.getElementById(id), {
center: {lat: lang, lng: long},
zoom: 13
});
var image = new google.maps.MarkerImage("/images/marker.png", null, null, null, new google.maps.Size(64,64));
var marker = new google.maps.Marker({
position: {lat: lang, lng: long},
map: map,
icon: image, // null = default icon
animation: google.maps.Animation.DROP,
title: 'Hello World!'
});
}
$(document).ready(function() {
$('.map').each(function() {
initMap($(this).attr('id'), parseFloat($(this).data('lat')), parseFloat($(this).data('lng')));
});
});