我没有任何以前的JavaScript经验。从回调返回值
我想实现以下功能,我希望用返回的值纬度和经度:
function get_address() {
var geocoder = new google.maps.Geocoder()
geocoder.geocode({ address: "SE-17270 Sverige"},
function(locResult) {
var lat = locResult[0].geometry.location.lat();
var lng = locResult[0].geometry.location.lng();
alert(lat);
alert(lng);
})
}
我该怎么办呢?
所以我想要做的是这样的:
function get_address(postcode)
{
var geocoder = new google.maps.Geocoder()
var lat
var lng
geocoder.geocode({ address: "SE-"+postcode+"Sverige"},
function(locResult) {
lat = locResult[0].geometry.location.lat();
lng = locResult[0].geometry.location.lng();
})
return lat,lng
}
'地址解析器。 geocode' is async ... – 2012-04-27 11:05:24