首页 文章

使用Google地方自动填充功能获取城市的place_id

提问于
浏览
1

我正在使用谷歌地方自动填充的输入字段 . 我已经设置了自动完成功能来预测只有城市,但我正在寻找一种简单的方法来获取所选城市的唯一place_id . 我不想在谷歌 Map 上使用它 . 我需要它只是为了确定所选城市的独特 Value ..提前感谢..

这是我的JS:

<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>

1 回答

相关问题