1
function setMaps() {
var geocoder = new google.maps.Geocoder();
var result = "";
$('.map_canvas').each(function(){
geocoder.geocode({
'address': $(this).attr('address'),
'region': 'de'
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
result += results[0].geometry.location.lng()+",";
result += results[0].geometry.location.lat();
} else {
result = "Unable to find address: " + status;
}
$(this).gmap({ 'center': result });
});
});
}
这种方法应该表现出一个页面上的多个地图。
HTML:
<div class="map_canvas" address="Berlin, Zoo">
</div>
问题是$(this).gmap({ 'center': result });
不起作用:
Uncaught TypeError: Cannot set property 'position' of undefined
任何想法如何将map_canvas提供对象传递给回调函数?