-1
我试图在单个页面上显示多个谷歌地图。具体数量的地图实例可能因页面而异。我发现这个代码在回答另一个问题,这似乎正是我需要的:单页上的多个谷歌地图
function mapAddress(mapElement, address) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var mapOptions = {
zoom: 14,
center: results[0].geometry.location,
disableDefaultUI: true
};
var map = new google.maps.Map(document.getElementById(mapElement), mapOptions);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
来源:https://stackoverflow.com/a/22328509/2740023
我不确定,我怎么会修改这个代码用正确的变量,使它工作。我可以访问lat和long变量以及文本字符串格式的地址。我究竟在哪里插入上述代码?