我需要在我的插件中添加一张地图,我知道如何在“公共网页”中做我需要的事情,就像我在这里所做的那样:http: //jsfiddle.net/hCymP/6/
问题是我真的不知道如何在 Firefox 插件中做到这一点。我尝试使用LoadSubScript导入脚本,并尝试在下一行添加 chrome html:
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
但没有任何效果。我找到的最佳解决方案是在我的函数中添加此文件中的部分代码(脚本 src 的代码),使用loadSubScript导入此文件,然后执行我的所有函数但返回一个空 div。
Components.utils.import("resource://gre/modules/Services.jsm");
window.google = {};
window.google.maps = {};
window.google.maps.modules = {};
var modules = window.google.maps.modules;
var loadScriptTime = (new window.Date).getTime();
window.google.maps.__gjsload__ = function(name, text) { modules[name] = text;};
window.google.maps.Load = function(apiLoad) {
delete window.google.maps.Load;
apiLoad([0.009999999776482582,[[["https://mts0.googleapis.com/vt?lyrs=m@227000000\u0026src=api\u0026hl=en-US\u0026","https://mts1.googleapis.com/vt?lyrs=m@227000000\u0026src=api\u0026hl=en-US\u0026"],null,null,null,null,"m@227000000"],[["https://khms0.googleapis.com/kh?v=134\u0026hl=en-US\u0026","https://khms1.googleapis.com/kh?v=134\u0026hl=en-US\u0026"],null,null,null,1,"134"],[["https://mts0.googleapis.com/vt?lyrs=h@227000000\u0026src=api\u0026hl=en-US\u0026","https://mts1.googleapis.com/vt?lyrs=h@227000000\u0026src=api\u0026hl=en-US\u0026"],null,null,null,null,"h@227000000"],[["https://mts0.googleapis.com/vt?lyrs=t@131,r@227000000\u0026src=api\u0026hl=en-US\u0026","https://mts1.googleapis.com/vt?lyrs=t@131,r@227000000\u0026src=api\u0026hl=en-US\u0026"],null,null,null,null,"t@131,r@227000000"],null,null,[["https://cbks0.googleapis.com/cbk?","https://cbks1.googleapis.com/cbk?"]],[["https://khms0.googleapis.com/kh?v=80\u0026hl=en-US\u0026","https://khms1.googleapis.com/kh?v=80\u0026hl=en-US\u0026"],null,null,null,null,"80"],[["https://mts0.googleapis.com/mapslt?hl=en-US\u0026","https://mts1.googleapis.com/mapslt?hl=en-US\u0026"]],[["https://mts0.googleapis.com/mapslt/ft?hl=en-US\u0026","https://mts1.googleapis.com/mapslt/ft?hl=en-US\u0026"]],[["https://mts0.googleapis.com/vt?hl=en-US\u0026","https://mts1.googleapis.com/vt?hl=en-US\u0026"]],[["https://mts0.googleapis.com/mapslt/loom?hl=en-US\u0026","https://mts1.googleapis.com/mapslt/loom?hl=en-US\u0026"]],[["https://mts0.googleapis.com/mapslt?hl=en-US\u0026","https://mts1.googleapis.com/mapslt?hl=en-US\u0026"]],[["https://mts0.googleapis.com/mapslt/ft?hl=en-US\u0026","https://mts1.googleapis.com/mapslt/ft?hl=en-US\u0026"]]],["en-US","US",null,0,null,null,"https://maps.gstatic.com/mapfiles/","https://csi.gstatic.com","https://maps.googleapis.com","https://maps.googleapis.com"],["https://maps.gstatic.com/intl/en_us/mapfiles/api-3/13/11","3.13.11"],[3047554353],1.0,null,null,null,null,1,"",null,null,1,"https://khms.googleapis.com/mz?v=134\u0026",null,"https://earthbuilder.googleapis.com","https://earthbuilder.googleapis.com",null,"https://mts.googleapis.com/vt/icon"], loadScriptTime);
};
//I can't use document.write but use loadSubScript insthead
Services.scriptloader.loadSubScript("chrome://googleMaps/content/Google-Maps-V3.js", window, "utf8"); //chrome://MoWA/content/Google-Maps-V3.js", window, "utf8");
var mapContainer = window.content.document.createElement('canvas');
mapContainer.setAttribute('id', "map");
mapContainer.setAttribute('style',"width: 500px; height: 300px");
mapContainer.style.backgroundColor = "red";
var mapOptions = {
center: new window.google.maps.LatLng(latitude, longitude),
zoom: 5,
mapTypeId: window.google.maps.MapTypeId.ROADMAP
}
var map = new window.google.maps.Map(mapContainer,mapOptions);
return mapContainer;
你能帮助我吗?我正在开发一个“Firefox for Android”插件,这就是为什么我需要做像 *window.content.*document.createElement 这样的事情,因为没有声明文档,只有窗口,我认为这可能是问题......但我如果我不知道 Google 地图使用什么,就无法声明所有内容。
补充:我还读到 Google Maps API 团队有特定的代码,不允许您在本地复制主脚本。特别是,该代码每隔这么多小时就会“过期”。我结合了这个脚本的一部分:https ://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false 因为我不能直接执行这个(错误:写调用了一个对象不实现接口 HTMLDocument)。所以我别无选择!