您无法从函数返回值,该函数返回时该值尚不存在。
该
geopre方法进行异步调用并使用回调来处理结果,因此您必须在
preLatLng函数中执行相同的 *** 作:
var geoprer;function initialize() { geoprer = new google.maps.Geoprer(); var latlng = new google.maps.LatLng(40.730885,-73.997383); preLatLng(function(addr){ alert(addr); });}function preLatLng(callback) { var latlng = new google.maps.LatLng(40.730885,-73.997383); if (geoprer) { geoprer.geopre({'latLng': latlng}, function(results, status) { if (status == google.maps.GeoprerStatus.OK) { if (results[1]) { callback(results[1].formatted_address); } else { alert("No results found"); } } else { alert("Geoprer failed due to: " + status); } }); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)