js loading:
<script src="https://maps.google.com/maps/api/js?key=AIzaSyC3Ws7EvlZS2PRlNFZfFrqOnlWM_XHYO1o&libraries=places" type="text/javascript"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
HTML代码:
<input type="text" class="textbox controls" placeholder="Post Code,City" id="cityzip" name="cityzip" value="">
JS代码:
<script>
$(document).ready(function () {
$(function(){
var autocomplete;
var geocoder;
var input = document.getElementById('cityzip');
var options = {
types: ['(regions)'] // (cities)
};
autocomplete = new google.maps.places.Autocomplete(input,options);
});
});
</script>
JS代码在关闭body标签之前放置。我在关闭头之前放置了Gmaps文件。我不知道为什么没有人能帮助我。
答案 0 :(得分:1)
我创造了一个小提琴,它的工作正常
$(document).ready(function () {
$(function(){
var autocomplete;
var geocoder;
var input = document.getElementById('cityzip');
var options = {
types: ['(regions)'] // (cities)
};
autocomplete = new google.maps.places.Autocomplete(input,options);
});
});
&#13;
<script src="https://maps.google.com/maps/api/js?key=AIzaSyC3Ws7EvlZS2PRlNFZfFrqOnlWM_XHYO1o&libraries=places" type="text/javascript"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<input type="text" class="textbox controls" placeholder="Post Code,City" id="cityzip" name="cityzip" value="">
&#13;