我正在使用带有Google地点自动完成功能的输入字段。我已将自动完成设置为仅预测城市,但我很难找到一种简单的方法来获取所选城市的唯一place_id。我不想在Google地图上使用它。我只需要用一个唯一值来标识所选城市即可。提前致谢。
以下是我的JavaScript代码:
以下是我的JavaScript代码:
<script src="maps.googleapis.com/maps/api/js?libraries=places"; type="text/javascript"></script>
<script type="text/javascript">
function initialize() {
var options = { types: ['(cities)'] };
var input = document.getElementById('searchCity');
var autocomplete = new google.maps.places.Autocomplete(input,options);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
以下是我的 PHP 代码:
<form method="GET" action=<?php echo $_SERVER['PHP_SELF'];?>>
<input id="searchCity" type="text" size="50"
placeholder="Enter a City" autocomplete="on" name="city">
<br>
<?php if (!empty($_GET['city']) ) {
echo $_GET['city'];
} else {
echo "not set";
}
unset($_GET['city']); ?>
</form>
<!-- Here I would like to show the place_id of the selected city-->
</div>
var input = document.getElementById('searchCity'); var autocomplete = new google.maps.places.Autocomplete(input,options); }
google.maps.event.addDomListener(window, 'load', initialize); </script> - maragos