Javascript 如何将对象传递到此js函数?
代码: 此方法应在一个页面上显示多个地图 HTML: 知道如何将map\u canvas对象传递给回调函数吗?试试以下方法:Javascript 如何将对象传递到此js函数?,javascript,jquery,Javascript,Jquery,代码: 此方法应在一个页面上显示多个地图 HTML: 知道如何将map\u canvas对象传递给回调函数吗?试试以下方法: Uncaught TypeError: Cannot set property 'position' of undefined 函数集映射(){ var geocoder=new google.maps.geocoder(); var结果=”; $('.map_canvas')。每个(函数(){ var_this=$(this)// <div class="map
Uncaught TypeError: Cannot set property 'position' of undefined
函数集映射(){
var geocoder=new google.maps.geocoder();
var结果=”;
$('.map_canvas')。每个(函数(){
var_this=$(this)//
<div class="map_canvas" address="Berlin, Zoo">
</div>
Uncaught TypeError: Cannot set property 'position' of undefined
function setMaps() {
var geocoder = new google.maps.Geocoder();
var result = "";
$('.map_canvas').each(function(){
var _this = $(this); // <------ here
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 }); // <---- and here
});
});
}