我正在使用谷歌自动填充地点javascript返回我的搜索框的建议结果,我需要的是只显示与输入的字符相关的城市和国家但谷歌api将给出很多我不需要的一般地方结果,所以如何限制结果只显示城市和国家.
我使用以下示例:
<html>
<head>
<style type="text/css">
body {
font-family: sans-serif;
font-size: 14px;
}
</style>
<title>Google Maps JavaScript API v3 Example: Places Autocomplete</title>
<script src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places" type="text/javascript"></script>
<script type="text/javascript">
function initialize() {
var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div>
<input id="searchTextField" type="text" size="50" placeholder="Enter a location" autocomplete="on">
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)