我不确定为什么以下不起作用。它根本不进入 geocoder.geocode 段。我想要的只是能够接收我输入的地址的地理编码,而无需将其绘制在任何地图上。
var geocoder;
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
alert(results[0].geometry.location);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
html代码:
<div>
<input id="address" type="textbox" value="Sydney, NSW">
<input type="button" value="Encode" onclick="codeAddress()">
</div>