使用的GoogleMap v3可反地理编码samplesource使此源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()和警报消息“称codeLatLng()1
,但不叫 “呼codeLatLng()2” 的代码不起作用
什么是错误的,我的代码?
任何消息:
这将更好地工作? –
没有控制台干净没有错误 – user2637015
我想尝试从数据处理功能中取出一些代码,只留下警报。另外,我会在数据处理函数之后放置另一个警报,但仍然在codeLatLng()函数中。 – Seano666