搜索框Google Maps API无法显示自动完成
我正在为位置搜索创建地图,但我的搜索框不显示自动完成功能。我按照 https://www.youtube.com/watch 上的教程进行操作?v=D_jUFC-Xktk&t=3s
这是我的地图,未显示自动完成
index.blade.php
<script async src="https://maps.googleapis.com/maps/api/js?key=keysensor&libraries=places"></script>
<div class="row">
<div class="col-lg-12">
<style>
#map {
width: 100%;
height: 500px;
}
</style>
<label for=""><b>ADRESSTANAH <font style="color: red;">*</font></b></label>
<div class="form-group">
<input type="text" id="searchmap">
<div id="map"></div>
</div>
</div>
var map = new google.maps.Map(document.getElementById('map'),{
center:{
lat:-6.8909965,
lng:110.6046387
},
zoom:15
});
var marker = new google.maps.Marker({
position: {
lat:-6.8909965,
lng:110.6046387
},
map : map,
draggable : true
});
var searchBox = new google.maps.places.SearchBox(document.getElementById('searchmap'));
google.maps.event.addListener(searchBox, 'places_changed', function(){
var places = searchBox.getPlaces();
var bounds = new google.maps.LatLngBounds();
var i, place;
for(i=0; place=places[i];i++){
bounds.extends(place.geometry.location);
marker.setPosition(place.geometry.location);
}
map.fitBounds(bounds);
map.setZoom(15);
});
google.maps.event.addListener(marker, 'position_changed', function(){
var lat = marker.getPosition().lat();
var lng = marker.getPosition().lng();
$('#lat').val(lat);
$('#lng').val(lng);
});
我想在搜索框中显示自动完成功能。请帮我解决它。感谢你。
I'm creating a map for a location search but my searchbox doesn't show autocomplete. I followed the tutorial on https://www.youtube.com/watch?v=D_jUFC-Xktk&t=3s
this is my map not showing autocompelete
index.blade.php
<script async src="https://maps.googleapis.com/maps/api/js?key=keysensor&libraries=places"></script>
<div class="row">
<div class="col-lg-12">
<style>
#map {
width: 100%;
height: 500px;
}
</style>
<label for=""><b>ADRESSTANAH <font style="color: red;">*</font></b></label>
<div class="form-group">
<input type="text" id="searchmap">
<div id="map"></div>
</div>
</div>
var map = new google.maps.Map(document.getElementById('map'),{
center:{
lat:-6.8909965,
lng:110.6046387
},
zoom:15
});
var marker = new google.maps.Marker({
position: {
lat:-6.8909965,
lng:110.6046387
},
map : map,
draggable : true
});
var searchBox = new google.maps.places.SearchBox(document.getElementById('searchmap'));
google.maps.event.addListener(searchBox, 'places_changed', function(){
var places = searchBox.getPlaces();
var bounds = new google.maps.LatLngBounds();
var i, place;
for(i=0; place=places[i];i++){
bounds.extends(place.geometry.location);
marker.setPosition(place.geometry.location);
}
map.fitBounds(bounds);
map.setZoom(15);
});
google.maps.event.addListener(marker, 'position_changed', function(){
var lat = marker.getPosition().lat();
var lng = marker.getPosition().lng();
$('#lat').val(lat);
$('#lng').val(lng);
});
I want to show autocomplete in the searchbox. please help me to solve it. thank u.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在请求中有一个回调参数,该参数将调用要执行的需要。例如:
然后,您将将所有JavaScript代码放在
initmap
函数中。这是一个有效的jsbin样本: https:/ ?HTML,JS,控制台,输出You need to have a callback parameter in your request that would call the needs to be executed. For example:
Then, you will put all javascript code inside the
initMap
function. Here is a working JSBin sample: https://jsbin.com/qerofoqudo/edit?html,js,console,output