【发布时间】:2013-09-27 11:18:54
【问题描述】:
我正在尝试将 Google API 中的地图加载到 div 中。但是,地图没有加载,也没有输出错误。这是代码:
// google maps
var geocoder, map;
function codeAddress(address) {
geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var myOptions = {
zoom: 8,
center: results[0].geometry.location,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
}
});
}
google.maps.event.addDomListener(window, 'load', function() {
codeAddress('" . $location['address'] . " " . $location['zip'] . " " . $location['city'] . " " . $countries[$location['country']] . "');
});
我已经处理这个问题很长时间了,我没有想法。
你们中的任何人都熟悉 google maps api,谁知道我的代码有什么问题?我的 div 确实存在,ID 为:map_canvas。
【问题讨论】:
-
你能多发点吗?我认为这不足以调试代码。
-
要么你传递到
codeAddress的地址很奇怪,要么你没有设置你的地图所在的div的宽度/高度。因为如果我只传入',你的代码就可以工作伦敦'到codeAddress。
标签: javascript jquery google-maps google-maps-api-3