我想建立一個谷歌地方自動完成國際化。通過選擇一種語言,應用程序應該爲該語言加載正確的Google API。谷歌地圖API後頁面加載電話
現在我有這樣的JS代碼:
function loadScript(src) {
var script = document.createElement("script");
document.body.appendChild(script);
script.src = src;
};
$('#' + country_id).change(function(){
delete google.maps;
$('script').each(function() {
if (this.src.indexOf('googleapis.com/maps') >= 0
|| this.src.indexOf('maps.gstatic.com') >= 0
|| this.src.indexOf('earthbuilder.googleapis.com') >= 0) {
// console.log('removed', this.src);
$(this).remove();
}
});
loadScript("http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false&language=" + this.value);
setTimeout(function(){ google_address(input_id, options_type, country_id, auto_complete) }, 2000);
});
其中GOOGLE_ADDRESS是設置自動完成的功能。此解決方案不起作用,把我扔鉻錯誤:
Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.
還試圖用的google.load,但沒有更多的成功......
任何想法將非常歡迎。
爲什麼-1?這不公平... – knotito 2014-10-16 15:22:08