![](/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.