gpt4 book ai didi

javascript - Bootstrap 模式对话框中的谷歌地图自动完成结果

转载 作者:IT王子 更新时间:2023-10-29 02:52:43 25 4
gpt4 key购买 nike

我在 Twitter Bootstrap 模态对话框中有一个 Google map 自动完成输入字段,但未显示自动完成结果。但是,如果我按下向下箭头键,它会选择下一个自动完成结果,因此自动完成代码似乎可以正常工作,只是结果显示不正确。也许它隐藏在模态对话框后面?

截图如下:

Typing something in the autocomplete field gives nothing在自动完成字段中输入内容不会产生任何结果

Pressing the arrow down key gives the first result按向下箭头键给出第一个结果

和代码:

<div class="modal hide fade" id="map_modal">
<div class="modal-body">
<button type="button" class="close" data-dismiss="modal">×</button>
<div class="control-group">
<label class="control-label" for="keyword">Cari alamat :</label>
<div class="controls">
<input type="text" class="span6" name="keyword" id="keyword">
</div>
</div>
<div id="map_canvas" style="width:530px; height:300px"></div>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal">Close</a>
<a href="#" class="btn btn-primary">Save changes</a>
</div>

<script type="text/javascript">
$("#map_modal").modal({
show: false
}).on("shown", function()
{
var map_options = {
center: new google.maps.LatLng(-6.21, 106.84),
zoom: 11,
mapTypeId: google.maps.MapTypeId.ROADMAP
};

var map = new google.maps.Map(document.getElementById("map_canvas"), map_options);

var defaultBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(-6, 106.6),
new google.maps.LatLng(-6.3, 107)
);

var input = document.getElementById("keyword");
var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.bindTo("bounds", map);

var marker = new google.maps.Marker({map: map});

google.maps.event.addListener(autocomplete, "place_changed", function()
{
var place = autocomplete.getPlace();

if (place.geometry.viewport) {
map.fitBounds(place.geometry.viewport);
} else {
map.setCenter(place.geometry.location);
map.setZoom(15);
}

marker.setPosition(place.geometry.location);
});

google.maps.event.addListener(map, "click", function(event)
{
marker.setPosition(event.latLng);
});
});
</script>

我已尽力自己解决这个问题,但由于我不知道自动完成结果的 html 和 css(检查元素什么也没给出),我现在迷路了。有帮助吗?

先谢谢了!

最佳答案

问题出在 .modalz-index

使用此 CSS 标记:

.pac-container {
background-color: #FFF;
z-index: 20;
position: fixed;
display: inline-block;
float: left;
}
.modal{
z-index: 20;
}
.modal-backdrop{
z-index: 10;
}​

您还可以查看最终演示 here

ps:感谢@lilina 在 jsfiddle.com 上的演示

关于javascript - Bootstrap 模式对话框中的谷歌地图自动完成结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10957781/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com