html文件中的表单传递一个名为" address"的输入。到一个php文件" registerEvent.php"在哪里进行地理编码。无论输入什么地址,该功能仍然在警报中输出ZERO_RESULTS状态,如果输入的地址无效(即,NULL或不可能的地址),则可能发生该状态。我已经测试过,接收到html表单中的地址值在php和codeAddress()函数的开头都能正常工作。
<?php
$geoadrese = $_POST['address'];
?>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js"></script>
<script type="text/javascript">
geocoder = new google.maps.Geocoder();
var inputLat;
var inputLng;
function codeAddress() {
var address = '<?php echo $geoadrese; ?>';
// everything works fine up until this point
geocoder.geocode( { 'address': address }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
inputLat = results[0].geometry.location.lat();
inputLng = results[0].geometry.location.lng();
window.location.href = "registerEvent.php?inputLat=" + inputLat + "&inputLng=" + inputLng;
} else {
alert('Geocode was not successful for the following reason: ' + status);
};
});
}
codeAddress();
</script>