谷歌地图地址建议

4
有人知道是否有办法使用Google Maps API在我的网页上复制类似http://maps.google.com/中的ajax建议框吗?
例如,如果有人写下“15大道”,则会出现一系列建议:
“美国纽约市大道15号”
“美国加利福尼亚州洛杉矶市星光大道15号”
等等
只是一个简单的是或否的问题 =)
谢谢
3个回答

6

3
这是谷歌的一个API示例。
请确保加载 places 库:
<script type="text/javascript"
    src="https://maps.googleapis.com/maps/api/js?v=3&libraries=places">
</script>

下面是你的 JavaScript 代码:
var autocomplete;
function initialize() {
    autocomplete = new google.maps.places.Autocomplete(
        document.getElementById('autocomplete'),
        { types: ['geocode'] }
    );
}
google.maps.event.addDomListener(window, 'load', initialize);

使用HTML
<div><input id="autocomplete" type="text"></div>

也可以参见https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接