【发布时间】:2011-07-30 15:07:57
【问题描述】:
我使用 Sencha Touch 和 Phonegap 构建了一个小应用程序。
在这个应用程序中,我需要谷歌地图 API,因为我想显示地图。
如果设备没有互联网连接,则会出现问题,因此无法在 html 中加载 google maps API。所以我检查了互联网连接。
如果互联网连接可用,我尝试使用 Ext.data.connection 加载谷歌地图 API:
var conn = new Ext.data.Connection();
var url = 'http://maps.google.com/maps/api/js?sensor=true&';
conn.request({
url: url,
callback: function(options, success, response){
if(response && response.responseText){
// do something
}
},
method:'GET'}
);
如果我在 google chrome 中测试应用程序,我会收到以下错误:XMLHttpRequest cannot load @987654321@;_dc=1302077479281. Origin null is not allowed by Access-Control-Allow-Origin.
无论我尝试通过file:/// 还是通过网络服务器 (http://localhost/app) 调用 HTML 都没有关系
如何获取 google maps API 并“绕过”或避免这种访问控制行为?
【问题讨论】:
标签: javascript google-chrome xmlhttprequest cordova sencha-touch