不要使用 id 选择器,使用其他东西,比如类选择器。
var map = new google.maps.Map($('.map')[0], myOptions);
如果您有多个地图选择器,您可以遍历包含它们的列表元素,并单独初始化每个。
$('.map-listing-element').each(function(){
var mapElement = $(this).find('.map-canvas');
var options = {...}; // whatever the options are
var googleMap = new google.maps.Map(mapElement[0], options);
});
<div class="this-box-wraps-all-maps">
<div class="map-listing-element">
...load your partial views wrapped in this element
Map 1
<div class="map-canvas"></div>
</div>
<div class="map-listing-element">
...load your partial views wrapped in this element
Map 2
<div class="map-canvas"></div>
</div>
<div class="map-listing-element">
...load your partial views wrapped in this element
Map 3
<div class="map-canvas"></div>
</div>
<div class="map-listing-element">
...load your partial views wrapped in this element
Map N
<div class="map-canvas"></div>
</div>
</div>