0
我的插件使用Google Maps API在用户在输入字段中键入几个字母时自动建议位置。冲突的Google地图API
要做到这一点,我在排队谷歌地图API如下:
wp_register_script('auto_location_map_library', 'http://maps.googleapis.com/maps/api/js?key=' . get_option('auto_location_maps_key') . '&sensor=false&libraries=places', array('jquery'), '1.0', false);
wp_enqueue_script('auto_location_map_library');
一切工作正常,我得到自动的建议。但是,只要在已经包含Google地图库的主题上进行测试,就会完全崩溃。
我试过在我的插件中插入主题的库调用,但是这并没有工作,并不是一个很好的解决方案。
有没有一种类似于jQuery中使用的我不知道的noConflict Google Maps调用?
由于利益的问题,对于引用自我暗示的代码如下:
jQuery(document).ready(function() {
function initialize() {
var autocompleteOptions = {
<?php if (!(get_option('auto_location_countrycode') == '')) { ?>
componentRestrictions: {country: '<?php echo get_option('auto_location_countrycode'); ?>'},
<?php } ?>
};
if (jQuery('#search_location').length) {
var input = document.getElementById('search_location');
var autocomplete = new google.maps.places.Autocomplete(input, autocompleteOptions);
}
}
google.maps.event.addDomListener(window, 'load', initialize);
});
看看你在运行谷歌地图时发现的萤火虫? –
@Mahmood - 在Chrome控制台中,我收到“警告:您已在此页面上多次包含Google Maps API,这可能会导致意外错误。” –
删除后面的'google API'并尝试。 –