admin管理员组文章数量:1425051
I use Sencha Touch and Phonegap to build a small app.
In this app I need the google maps API as I want to display a map.
There is a problem if the device has no internet connection, so the google maps API couldn't be loaded in the html. So I check for the internet connection.
If the internet connection is available I try to load the google maps API with Ext.data.connection:
var conn = new Ext.data.Connection();
var url = ';';
conn.request({
url: url,
callback: function(options, success, response){
if(response && response.responseText){
// do something
}
},
method:'GET'}
);
If I test the app in google chrome I receive following error: XMLHttpRequest cannot load ;amp;_dc=1302077479281. Origin null is not allowed by Access-Control-Allow-Origin.
It doesn't matter if I try to invoke the HTML via file:///
or via a webserver (http://localhost/app
)
How can I get the google maps API and "bypass" or avoid this Access-Control-behaviour?
I use Sencha Touch and Phonegap to build a small app.
In this app I need the google maps API as I want to display a map.
There is a problem if the device has no internet connection, so the google maps API couldn't be loaded in the html. So I check for the internet connection.
If the internet connection is available I try to load the google maps API with Ext.data.connection:
var conn = new Ext.data.Connection();
var url = 'http://maps.google./maps/api/js?sensor=true&';
conn.request({
url: url,
callback: function(options, success, response){
if(response && response.responseText){
// do something
}
},
method:'GET'}
);
If I test the app in google chrome I receive following error: XMLHttpRequest cannot load http://maps.google./maps/api/js?sensor=true&_dc=1302077479281. Origin null is not allowed by Access-Control-Allow-Origin.
It doesn't matter if I try to invoke the HTML via file:///
or via a webserver (http://localhost/app
)
How can I get the google maps API and "bypass" or avoid this Access-Control-behaviour?
Share Improve this question asked Apr 6, 2011 at 8:34 heringhering 1,9544 gold badges29 silver badges43 bronze badges2 Answers
Reset to default 3Hering, sorry, this won't be an easy answer.
I think you want to use a conditional script loader. These are api's that will add the script to the document only if a condition (you have a network connection) is met.
A good one is http://yepnopejs./
According to this thread, it is possible to load google maps, but you must do as it says in the thread. Google Maps with YepNope
Specifically, include yepnope.js and remove any references to google maps.
yepnope([{
load: 'http://www.google./jsapi',
callback: function(){
google.load("maps", "3", {
callback: function(){
console.log("loaded");
},
other_params: "sensor=false"
});
}
}]);
When it is time to render the map (which must be done after Google Maps is fully loaded) make sure you add the Ext.Map card, then call:
this.doLayout();
I think this'll work great for you, it's working for me...
I found some instructions from google, so the following will work:
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.google./maps/api/js?sensor=true&callback=initializeMap";
document.body.appendChild(script);
本文标签:
版权声明:本文标题:javascript - Load google maps API when internet is available via Ext.data.connection Sencha Touch and Phonegap - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745419787a2657850.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论