JavaScript 错误 - 找不到变量:谷歌
我编写的代码在浏览器上运行得非常好。但是当我连接到 iPhone 上的 wifi 时,我在调试器中收到错误: Javascript 错误 - 找不到变量:google
每当我调用任何 google 地图/方向/geoLocation 对象时,都会发生这种情况。
代码如下:
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.');
}
}
}
})
});
每当代码遇到单词 google 时就会发生错误。另外,对于 LatLng 对象,我收到 javascript 错误:“...LatLng 的结果不是构造函数”
注意:变量“lats”和“longs”已在这段代码之前定义了 n 个给定值
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
对我有用的方法是:从 中删除“https”,
这样
我不知道为什么 Safari 不会在不安全的页面上加载安全页面,但它似乎没有。然后抛出错误。这是唯一一个具有这种行为的移动浏览器。
What worked for me: remove the "https" from the
so it becomes
I don't know why Safari doesn't load secure pages on unsecured ones but it just doesn't seem to. And then throws the error. This is the only mobile browser that seems to behave like that.
所以我之前已经将其作为评论发布了,但由于这是问题的实际解决方案,我将再次发布它:D
好吧,事实证明我收到所有这些错误的原因是因为我在代理后面。奇怪的是,当我使用 LAN 电缆连接时,代理允许我访问 google 库和服务器,但当我使用 WiFi 时则不允许。希望遇到这种错误的其他人会发现这有点帮助:)
So I had posted this earlier as a comment, but since this is the actual solution to the problem, I'm gonna post it once more :D
Ok turns out that the reason I was getting all those errors is cos I was behind a proxy. Weirdly enough the proxy lets me access the google libraries and server when I'm connected using the LAN cable, but not when Im using WiFi. Hope some1 else who's stuck wid this kind of error will find this somewhat helpful :)
您是否正在从 Google 服务器加载 Google JavaScript 库?如果是这样,当你没有 WiFi 时,这是行不通的。这就是为什么“google”对象没有定义。您只能在设备在线时使用 Google 地图等。
编辑:没关系,你说过你是通过 WiFi 连接的。奇怪的。我想我们需要查看您的完整源代码。
Could it be that you're loading the Google JavaScript libraries from the Google server? If so, when you don't have WiFi, that won't work. That's why the "google" object is not defined. You can only use Google Maps and such when you're device is online.
EDIT: Nevermind, you said you ARE connected via WiFi. Odd. I guess we need to see your full source code then.
我的解决方案是简单地确保 Google Maps js 在 Touch js 之前加载。只需将
放在前面
My solution was to simply make sure the Google Maps js loads before the Touch js. Simply put
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
before
<script id="microloader" type="text/javascript" src="touch/microloader/development.js"</script>
检查您的 config.xml 是否有权导航到您在 index.html 中写入的 Google Api 地址。
仔细检查您是否使用“https”或“http”。我在你的index.html中使用'https'
:
在你的config.xml中
这对我有用!
Check if your config.xml have permission to navigate into Google Api Address that you write in index.html.
Double check if you are working with 'https' or 'http'. I did with 'https'
In your index.html:
In your config.xml
This worked for me!