所以我正在使用谷歌地图 API,我想获得地理编码的位置结果。这就是我目前所拥有的:
var pinProperties = {};
geocoder.geocode( {"address": address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
pinProperties.markerPos = results[0].geometry.location;
}
else if (status === "ZERO_RESULTS") {
pinProperties.markerPos = map.getCenter();
}
else {
alert("Geocode was not successful for the following reason: " + status);
}
});
console.log(pinProperties.markerPos);
但是,即使满足前两个条件之一,pinProperties.markerPos 也会返回 undefined。我需要能够从地理编码外部访问该位置。提前致谢!