我写的代码在浏览器上运行得非常好。但是当我在iPhone上连接wifi时,我在调试器中得到一个错误: Javascript error - Can't find variable : google
每当我调用任何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.');
}
}
}
})
});
只要代码遇到单词google,就会出现错误。另外,对于LatLng对象,我得到了javascript错误:"....result of LatLng not a constructor“
注意:在这段代码之前,变量"lats“和”long“已经被定义为n个给定值
发布于 2012-07-09 12:59:06
因此,我之前发布了这篇文章作为评论,但由于这是问题的实际解决方案,我将再次发布:D
好的,事实证明,我得到所有这些错误的原因是因为我在代理后面。奇怪的是,当我使用局域网电缆连接时,代理允许我访问谷歌的库和服务器,但当我使用WiFi连接时,它却不允许。希望被这种错误困扰的some1其他人会发现这对他们有所帮助:)
发布于 2012-06-07 01:48:17
对我有效的方法:从
<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不在不安全的页面上加载安全页面,但它似乎就是不这样做。然后抛出错误。这是唯一一个看起来像这样的移动浏览器。
发布于 2011-10-11 18:42:29
会不会是你正在从Google服务器加载Google JavaScript库?如果是这样的话,当你没有WiFi的时候,这是行不通的。这就是为什么没有定义"google“对象的原因。只有当你的设备在线时,你才能使用谷歌地图之类的东西。
编辑:不要紧,你说你是通过WiFi连接的。很奇怪。我想我们需要看看你的全部源代码。
https://stackoverflow.com/questions/7567602
复制相似问题