gpt4 book ai didi

javascript - 谷歌地图自动完成在模式弹出窗口中不起作用

转载 作者:行者123 更新时间:2023-12-03 07:16:39 24 4
gpt4 key购买 nike

我正在使用谷歌地图 api。我正在尝试为输入框实现自动完成地址功能。但问题在于页面中的一切似乎都正常,但在模式弹出窗口中同样不起作用。

这是html

    <div class="col-xs-5 col-sm-2 col-md-2">
<a href="javascript:void(0)" data-ng-click="addlocationpopup()">+New
Location</a>
</div> <!--button which calls popup -->

这是模态弹出窗口
    <div class="modal right fade addlocation" id="myModal_5" tabindex="-1"
role="dialog" aria-labelledby="myModalLabel2" data-keyboard="false">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel1">ENTER LOCATION
DETAILS</h4>
</div>
<form name="locationForm" novalidate="novalidate" method="post">
<div class="modal-body">
<div class="row">
<div>
<input id="autocomplete" placeholder="Enter your address"
onFocus="geolocate()" type="text"></input>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<script
src="https://maps.googleapis.com/maps/api/js?
key=mykey&libraries=places&callback=initAutocomplete" async defer>
</script>
<script>
var placeSearch, autocomplete;
var componentForm = {
street_number: 'short_name',
route: 'long_name',
locality: 'long_name',
administrative_area_level_1: 'short_name',
country: 'long_name',
postal_code: 'short_name'
};

function initAutocomplete() {
autocomplete = new google.maps.places.Autocomplete(
/** @type {!HTMLInputElement} */(document.getElementById('autocomplete')),
{types: ['geocode']});
autocomplete.addListener('place_changed', fillInAddress);
}

function fillInAddress() {
var place = autocomplete.getPlace();

for (var component in componentForm) {
document.getElementById(component).value = '';
document.getElementById(component).disabled = false;
}

for (var i = 0; i < place.address_components.length; i++) {
var addressType = place.address_components[i].types[0];
if (componentForm[addressType]) {
var val = place.address_components[i][componentForm[addressType]];
document.getElementById(addressType).value = val;
}
}
}

function geolocate() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var geolocation = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
var circle = new google.maps.Circle({
center: geolocation,
radius: position.coords.accuracy
});
autocomplete.setBounds(circle.getBounds());
});
}
}
</script>

Controller . js :
    $scope.addlocationpopup = function(){
$(".addlocation").modal("show");
}

如果在页面中我放了一个输入框并输入它工作正常。但在模式内它不起作用,这是当我在输入框中输入时没有显示这些地方。我不明白为什么它在弹出窗口中不起作用,因为脚本是页面加载时已经加载。谁能告诉如何使它在模式弹出窗口中工作?

最佳答案

自动完成 建议的结果在那里,但隐藏在具有更高 的弹出/模态窗口下方z 指数 值(value)。要解决此问题,请将以下 CSS 添加到您的样式表中:

div.pac-container {
z-index: 99999999999 !important;
}

关于javascript - 谷歌地图自动完成在模式弹出窗口中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50365082/

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