Exception in setTimeout callback: ReferenceError: google is not defined
Exception in setTimeout callback: ReferenceError: google is not defined
我想我在 Stack Overflow 上一遍又一遍地问过同样的问题。我一直在尝试设置 Geocomplete 以与我的 Meteor js 应用程序一起使用。
同样的代码在非 Meteor 应用程序上运行得非常好,但在 Meteor js 应用程序上它只是被证明是顽固的。在阅读了论坛上的许多建议后进行了修改,我想出了这段代码。 运行 它给出了以下错误。
渲染函数代码:
Template.geolayout.onRendered(function(){
Meteor.setTimeout(function () {
$(function () {
$('body').append('<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyA55ihs_QPBpO5r465dgdfg1TJ0FX4ofL8zk&libraries=places">');
$('body').append('<script src="/js/jquery.geocomplete.js">');
$("#geocomplete").geocomplete({
map: ".map_canvas",
details: "form",
types: ["geocode", "establishment"],
});
$("#find").click(function(){
$("#geocomplete").trigger("geocode");
});
});
}, 200);
});
火焰代码
<template name="geolayout">
<div class="map_canvas"></div>
<form>
<input id="geocomplete" type="text" placeholder="Type in an address" value="Empire State Bldg" />
<input id="find" type="button" value="find" />
<fieldset>
<h3>Address-Details</h3>
<label>Name</label>
<input name="name" type="text" value="">
<label>URL</label>
<input name="url" type="text" value="">
<label>Website</label>
<input name="website" type="text" value="">
</fieldset>
</form>
</template>
控制台错误:
Exception in setTimeout callback: ReferenceError: google is not defined
at GeoComplete.$.extend.initMap (eval at <anonymous> (http://localhost:3000/packages/jquery.js?hash=c57b3cfa0ca9c66400d4456b6f6f1e486ee10aad:397:22), <anonymous>:123:22)
at GeoComplete.$.extend.init (eval at <anonymous> (http://localhost:3000/packages/jquery.js?hash=c57b3cfa0ca9c66400d4456b6f6f1e486ee10aad:397:22), <anonymous>:105:12)
at new GeoComplete (eval at <anonymous> (http://localhost:3000/packages/jquery.js?hash=c57b3cfa0ca9c66400d4456b6f6f1e486ee10aad:397:22), <anonymous>:99:10)
at HTMLInputElement.eval (eval at <anonymous> (http://localhost:3000/packages/jquery.js?hash=c57b3cfa0ca9c66400d4456b6f6f1e486ee10aad:397:22), <anonymous>:586:22)
at Function.jQuery.extend.each (http://localhost:3000/packages/jquery.js?hash=c57b3cfa0ca9c66400d4456b6f6f1e486ee10aad:442:23)
at jQuery.fn.jQuery.each (http://localhost:3000/packages/jquery.js?hash=c57b3cfa0ca9c66400d4456b6f6f1e486ee10aad:194:17)
at $.fn.geocomplete (eval at <anonymous> (http://localhost:3000/packages/jquery.js?hash=c57b3cfa0ca9c66400d4456b6f6f1e486ee10aad:397:22), <anonymous>:582:19)
at HTMLDocument.<anonymous> (http://localhost:3000/app/app.js?hash=a15884274aa7ef8a6a17bc31acbc671588e8bcb5:568:22)
at fire (http://localhost:3000/packages/jquery.js?hash=c57b3cfa0ca9c66400d4456b6f6f1e486ee10aad:3201:30)
at Object.self.add [as done] (http://localhost:3000/packages/jquery.js?hash=c57b3cfa0ca9c66400d4456b6f6f1e486ee10aad:3247:7)
只需移动 main.html 末尾的 2 个脚本标签。这应该有效,让您的生活更轻松。
<body>
{{> geolayout}}
<script src="http://maps.googleapis.com/maps/api/js?key=YOUR_KEY&libraries=places"></script>
<script src="/js/jquery.geocomplete.js"></script>
</body>
用您的 API 密钥替换 YOUR_KEY。
我想我在 Stack Overflow 上一遍又一遍地问过同样的问题。我一直在尝试设置 Geocomplete 以与我的 Meteor js 应用程序一起使用。
同样的代码在非 Meteor 应用程序上运行得非常好,但在 Meteor js 应用程序上它只是被证明是顽固的。在阅读了论坛上的许多建议后进行了修改,我想出了这段代码。 运行 它给出了以下错误。
渲染函数代码:
Template.geolayout.onRendered(function(){
Meteor.setTimeout(function () {
$(function () {
$('body').append('<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyA55ihs_QPBpO5r465dgdfg1TJ0FX4ofL8zk&libraries=places">');
$('body').append('<script src="/js/jquery.geocomplete.js">');
$("#geocomplete").geocomplete({
map: ".map_canvas",
details: "form",
types: ["geocode", "establishment"],
});
$("#find").click(function(){
$("#geocomplete").trigger("geocode");
});
});
}, 200);
});
火焰代码
<template name="geolayout">
<div class="map_canvas"></div>
<form>
<input id="geocomplete" type="text" placeholder="Type in an address" value="Empire State Bldg" />
<input id="find" type="button" value="find" />
<fieldset>
<h3>Address-Details</h3>
<label>Name</label>
<input name="name" type="text" value="">
<label>URL</label>
<input name="url" type="text" value="">
<label>Website</label>
<input name="website" type="text" value="">
</fieldset>
</form>
</template>
控制台错误:
Exception in setTimeout callback: ReferenceError: google is not defined
at GeoComplete.$.extend.initMap (eval at <anonymous> (http://localhost:3000/packages/jquery.js?hash=c57b3cfa0ca9c66400d4456b6f6f1e486ee10aad:397:22), <anonymous>:123:22)
at GeoComplete.$.extend.init (eval at <anonymous> (http://localhost:3000/packages/jquery.js?hash=c57b3cfa0ca9c66400d4456b6f6f1e486ee10aad:397:22), <anonymous>:105:12)
at new GeoComplete (eval at <anonymous> (http://localhost:3000/packages/jquery.js?hash=c57b3cfa0ca9c66400d4456b6f6f1e486ee10aad:397:22), <anonymous>:99:10)
at HTMLInputElement.eval (eval at <anonymous> (http://localhost:3000/packages/jquery.js?hash=c57b3cfa0ca9c66400d4456b6f6f1e486ee10aad:397:22), <anonymous>:586:22)
at Function.jQuery.extend.each (http://localhost:3000/packages/jquery.js?hash=c57b3cfa0ca9c66400d4456b6f6f1e486ee10aad:442:23)
at jQuery.fn.jQuery.each (http://localhost:3000/packages/jquery.js?hash=c57b3cfa0ca9c66400d4456b6f6f1e486ee10aad:194:17)
at $.fn.geocomplete (eval at <anonymous> (http://localhost:3000/packages/jquery.js?hash=c57b3cfa0ca9c66400d4456b6f6f1e486ee10aad:397:22), <anonymous>:582:19)
at HTMLDocument.<anonymous> (http://localhost:3000/app/app.js?hash=a15884274aa7ef8a6a17bc31acbc671588e8bcb5:568:22)
at fire (http://localhost:3000/packages/jquery.js?hash=c57b3cfa0ca9c66400d4456b6f6f1e486ee10aad:3201:30)
at Object.self.add [as done] (http://localhost:3000/packages/jquery.js?hash=c57b3cfa0ca9c66400d4456b6f6f1e486ee10aad:3247:7)
只需移动 main.html 末尾的 2 个脚本标签。这应该有效,让您的生活更轻松。
<body>
{{> geolayout}}
<script src="http://maps.googleapis.com/maps/api/js?key=YOUR_KEY&libraries=places"></script>
<script src="/js/jquery.geocomplete.js"></script>
</body>
用您的 API 密钥替换 YOUR_KEY。