【发布时间】:2013-11-21 13:07:44
【问题描述】:
使用 googlemap v3 反向地理编码示例源制作此源
var map;
var geocoder;
var marker;
function initialize() {
geocoder = new google.maps.Geocoder();
var mapOptions = {
zoom : 14,
center : new google.maps.LatLng(30, 30)
};
map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
}
function codeLatLng() {
var latlng = new google.maps.LatLng(30, 30);
alert("call codeLatLng() 1");
geocoder.geocode({'latLng': latlng}, function(results, status) {
alert("call codeLatLng() 2");
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
map.setZoom(11);
marker = new google.maps.Marker({
position: latlng,
map: map
});
infowindow.setContent(results[1].formatted_address);
infowindow.open(map, marker);
} else {
alert('No results found');
}
} else {
alert('Geocoder failed due to: ' + status);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
codeLatLng();
我调用函数codeLatLng();代码的最后一行
所以调用函数codeLatLng()和警告信息“call codeLatLng() 1
但不调用“call codeLatLng() 2”且代码不起作用
我的代码有什么问题?
【问题讨论】:
-
错误控制台中有任何消息吗?
-
没有控制台干净没有错误
-
我会尝试从数据处理函数中取出一些代码,只留下警报。另外,我会在数据处理函数之后放置另一个警报,但仍然在 codeLatLng() 函数中。
标签: javascript google-maps google-maps-api-3