Javascript jQuery位置选择器API位置名称字段不工作
我正在为地图视图使用jquery位置选择器API。该API中的所有内容都可以正常工作,但当我们输入位置名称时,它就不起作用了。此外,自动完成选项不起作用,地图不显示位置Javascript jQuery位置选择器API位置名称字段不工作,javascript,jquery,google-maps,jquery-plugins,Javascript,Jquery,Google Maps,Jquery Plugins,我正在为地图视图使用jquery位置选择器API。该API中的所有内容都可以正常工作,但当我们输入位置名称时,它就不起作用了。此外,自动完成选项不起作用,地图不显示位置 Location: <input type="text" id="location" style="width: 200px"/> Lat <input type="text" id="lat" style="width: 200px"/> Long: <input type="text" id="
Location: <input type="text" id="location" style="width: 200px"/>
Lat <input type="text" id="lat" style="width: 200px"/>
Long: <input type="text" id="lng" style="width: 200px"/>
<div id="us2" style="width: 500px; height: 400px;"></div>
<script>$('#us2').locationpicker({
location: {latitude: 46.15242437752303, longitude: 2.7470703125},
radius: 0,
inputBinding: {
latitudeInput: $('#lat'),
longitudeInput: $('#lng'),
locationNameInput: $('#location')
},
enableAutocomplete: true,
onchanged: function(currentLocation, radius, isMarkerDropped) {
alert("");
}
});
</script>
位置:
拉特
长:
$('#us2')。位置选择器({
地点:{纬度:46.15242437752303,经度:2.74703125},
半径:0,
输入绑定:{
纬度输入:$('lat'),
纵向输入:$('lng'),
locationNameInput:$(“#位置”)
},
enableAutocomplete:正确,
onchanged:函数(当前位置、半径、isMarkerDroped){
警报(“”);
}
});
最有可能发生这种情况,因为一旦位置选择器初始化,DOM尚未加载
尝试调用位置选择器初始化,如下所示:
$(function() {
$('#us2').locationpicker({
location: {latitude: 46.15242437752303, longitude: 2.7470703125},
radius: 0,
inputBinding: {
latitudeInput: $('#lat'),
longitudeInput: $('#lng'),
locationNameInput: $('#location')
},
enableAutocomplete: true,
onchanged: function(currentLocation, radius, isMarkerDropped) {
alert("Location changed. New location (" + currentLocation.latitude + ", " + currentLocation.longitude + ")");
}
});
});
最有可能发生这种情况,因为在初始化位置选择器之后,DOM尚未加载 尝试调用位置选择器初始化,如下所示:
$(function() {
$('#us2').locationpicker({
location: {latitude: 46.15242437752303, longitude: 2.7470703125},
radius: 0,
inputBinding: {
latitudeInput: $('#lat'),
longitudeInput: $('#lng'),
locationNameInput: $('#location')
},
enableAutocomplete: true,
onchanged: function(currentLocation, radius, isMarkerDropped) {
alert("Location changed. New location (" + currentLocation.latitude + ", " + currentLocation.longitude + ")");
}
});
});
我也有同样的问题。事实证明,如果使用带有API密钥的Google Maps API,则需要在Google开发者控制台中启用“Google Places API Web Service”。在我这样做之后,自动完成功能开始工作 我也有同样的问题。事实证明,如果使用带有API密钥的Google Maps API,则需要在Google开发者控制台中启用“Google Places API Web Service”。在我这样做之后,自动完成功能开始工作 您好,瓦迪姆,谢谢您的评论,但此脚本不仅在服务器上工作。我们尝试了您的代码,但它不工作。您好,瓦迪姆,感谢您的评论,但此脚本不仅在服务器上工作。我们尝试了您的代码,但它不工作。非常感谢您的帮助。我们尝试了一周,但没有发现问题。您的评论帮助很大。非常感谢您的帮助。我们尝试了一周,但没有发现问题。您的评论帮助很大。