我在这里分配了地点ID" placeid = results [0] .place_id"但它没有。它返回我未定义。分配操作在那里失败。
function match_up_dn(address)
{
geocoder = new google.maps.Geocoder();
var placeid;
if (geocoder)
{
geocoder.geocode({
'address': address
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
console.log("al:-"+results[0].place_id);
placeid = results[0].place_id;
}
else
{
alert("undefined address");
}
});
}
return placeid;
}
答案 0 :(得分:0)
试试这个
function match_up_dn(address)
{
geocoder = new google.maps.Geocoder();
var placeid;
geocoder.geocode({
'address': address
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
console.log("al:-"+results[0].place_id);
placeid = results[0].place_id;
return placeid;
}
else
{
alert("undefined address");
}
});
}