我试图在我的Siebel应用程序的一个文本字段中使用Google API实现地址自动完成功能。我不断收到错误“谷歌没有定义”。我正在使用jquery以下是我的代码:Google API用于地址自动完成不起作用
PhoneChangePR.prototype.BindData = function(a) {
SiebelAppFacade.PhoneChangePR.superclass.BindData.call(this, a);
$.getScript("http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js", function() {
console.log("Google maps successfully added");
});
$.getScript("http://maps.google.com/maps/api/js?sensor=false&libraries=places&language=en-AU", function() {
console.log("Second script loaded successfully");
});
var autocomplete = new google.maps.places.Autocomplete($("input[aria-labelledby=NewAddressLine1_Label]")[0], {});
google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();
console.log(place.address_components);
});
提前请help.Thanks。
'Google不要defined'通常在地图API的js没有加载发生。所以一定要正确加载你的脚本。 –
我得到了这个解决方案从http://stackoverflow.com/questions/4061125/autofill-address-google-maps-api 它似乎工作,当我在网上平台上试用它。我所做的一切是我已经改变了元素的名称。 –
我很好奇你在用jQuery做什么......当你引用'$ .getScript()'时,你使用的是jQuery,但是你在'http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js' ...但你必须已经在你的页面上有jQuery可用! – duncan