![](/img/trans.png)
[英]Angular - Javascript - Error: Can't find variable : google after reloading the page
[英]Javascript Error - Can't find variable : google
我写的代码在浏览器上运行得非常好。 但是当我在iPhone上连接到wifi时,我在调试器中出现错误:Javascript错误 - 无法找到变量:google
每当我调用任何谷歌地图/路线/地理位置对象时,就会发生这种情况。
代码如下:
map = new Ext.Map({
mapOptions : {
center : center,
zoom : 20,
// mapTypeId : google.maps.MapTypeId.ROADMAP,
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.DEFAULT
}
},
listeners : {
maprender : function(comp, map){
pos = new google.maps.LatLng(lats, longs, true);
var marker = new google.maps.Marker({
position: pos,
//title : 'Sencha HQ',
map: map
});
map.setMapTypeId(google.maps.MapTypeId.HYBRID);
setTimeout( function(){map.panTo (pos);} , 1000);
}
},
geo:new Ext.util.GeoLocation({
autoUpdate:true,
maximumAge: 0,
timeout:2000,
listeners:{
locationupdate: function(geo) {
pos = new google.maps.LatLng(lats, longs, true);
center = new google.maps.LatLng(geo.latitude, geo.longitude);
if (map.rendered)
map.update(center)
else
map.on('activate', map.onUpdate, map, {single: true, data: pos});
},
locationerror: function(geo, bTimeout, bPermissionDenied, bLocationUnavailable, message) {
if(bLocationUnavailable){
alert('Your Current Location is Unavailable on this device');
}
else if (bPermissionDenied){
alert('Location capabilities have been disabled on this device.');
}
}
}
})
});
只要代码遇到谷歌这个词,就会出现错误。 另外对于LatLng对象,我得到javascript错误:“.... LatLng的结果不是构造函数”
注意:变量“lats”和“longs”已在此段代码之前的给定值中定义
什么对我有用:删除“https”
<script src="https://maps.google.com/maps/api/js?sensor=false"></script>
所以它变成了
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
我不知道为什么Safari不会在不安全的页面上加载安全页面,但它似乎没有。 然后抛出错误。 这是唯一似乎表现得像这样的移动浏览器。
所以我之前作为评论发布了这个,但由于这是问题的实际解决方案,我将再次发布:D
好的结果是我得到所有这些错误的原因是因为我在代理后面。 奇怪的是,当我使用LAN电缆连接时,代理允许我访问谷歌库和服务器,但是当我使用WiFi时却没有。 希望其他一些被卡住这种错误的人会发现这有点帮助:)
您是否正在从Google服务器加载Google JavaScript库? 如果是这样,当你没有WiFi时,这将无法正常工作。 这就是为什么没有定义“谷歌”对象的原因。 当设备在线时,您只能使用谷歌地图等。
编辑:没关系,你说你通过WiFi连接。 奇。 我想我们需要查看完整的源代码。
我的解决方案是确保在Touch js之前加载Google Maps js。 简单的说
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
之前
<script id="microloader" type="text/javascript" src="touch/microloader/development.js"</script>
检查您的config.xml是否有权导航到您在index.html中编写的Google Api地址。 仔细检查您使用的是“https”还是“http”。 我用'https'做了
在index.html中:
`<script src="https://maps.google.com/maps/api/js?key=APIKEY" async defer type="text/javascript"></script>`
在你的config.xml中
`<access origin="https://maps.google.com/*" />
<allow-intent href="https://maps.google.com/*" />
<access origin="https://maps.gstatic.com/*" />
<allow-intent href="https://maps.gstatic.com/*" />
<access origin="https://maps.googleapis.com/*" />
<allow-intent href="https://maps.googleapis.com/*" />
<access origin="https://fonts.googleapis.com/*" />
<allow-intent href="https://fonts.googleapis.com/*" />`
这对我有用!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.