Javascript 错误 - 找不到变量:谷歌 [英] Javascript Error - Can't find variable : google

查看:16
本文介绍了Javascript 错误 - 找不到变量:谷歌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的代码在浏览器上运行得非常好.但是当我在 iPhone 上连接到 wifi 时,我在调试器中收到一个错误:Javascript 错误 - 找不到变量:google

每当我调用任何 google maps/directions/geoLocation 对象时都会发生这种情况.

<小时>

代码如下:

map = new Ext.Map({地图选项:{中心:中心,缩放:20,//mapTypeId : google.maps.MapTypeId.ROADMAP,导航控制:真,导航控制选项:{样式:google.maps.NavigationControlStyle.DEFAULT}},听众:{地图渲染:功能(补偿,地图){pos = new google.maps.LatLng(lats, longs, true);var 标记 = 新的 google.maps.Marker({职位: pos,//title : '煎茶总部',地图:地图});map.setMapTypeId(google.maps.MapTypeId.HYBRID);setTimeout( function(){map.panTo (pos);} , 1000);}},地理:新 Ext.util.GeoLocation({自动更新:真,最大年龄:0,超时:2000,听众:{位置更新:功能(地理){pos = new google.maps.LatLng(lats, longs, true);center = new google.maps.LatLng(geo.latitude, geo.longitude);如果(地图渲染)地图更新(中心)别的map.on('activate', map.onUpdate, map, {single: true, data: pos});},位置错误:功能(地理,bTimeout,bPermissionDenied,bLocationUnavailable,消息){如果(bLocationUnavailable){alert('您的当前位置在此设备上不可用');}否则如果(bPermissionDenied){alert('此设备上的定位功能已被禁用.');}}}})});

每当代码遇到 google 一词时就会发生错误.同样对于 LatLng 对象,我收到了 javascript 错误:....LatLng 的结果不是构造函数"

注意:变量lats"和longs"在这段代码之前已经定义了n个给定的值

解决方案

所以我早些时候发布了这个作为评论,但由于这是问题的实际解决方案,我将再次发布 :D

好吧,事实证明我收到所有这些错误的原因是因为我在代理后面.奇怪的是,当我使用 LAN 电缆连接时,代理允许我访问谷歌库和服务器,但当我使用 WiFi 时则不能.希望其他陷入这种错误的人会发现这有些帮助:)

The code I wrote runs absolutely fine on the browser. But when I connect to wifi on the iPhone I get an error in the debugger : Javascript Error - Can't find variable : google

This occurs whenever I call any google maps/directions/geoLocation object.


The code is as follows :

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.');
                 }      
             }
         }
     })
});

The error occurs whenever the code encounters the word google. Also for the LatLng object I get the javascript error : "....result of LatLng not a constructor"

Note : the variables "lats" and "longs" have been defined n given values before this segment of code

解决方案

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 :)

这篇关于Javascript 错误 - 找不到变量:谷歌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆