谷歌地图没有显示?Cordova插件
Google map not displaying? Cordova plugin
我遵循了以下链接说明,只是测试是否出现了映射。所以我进入了第四阶段,地图应该显示在那里,但我什么也没得到。(http://www.christianengvall.se/phonegap-and-google-maps/)
我已经添加了JS和CSS文件的所有引用,以及安装谷歌地图插件。
我更改了ondeviceready函数,因为我已经将该函数用于其他代码,所以应该在单击提交按钮时初始化映射。这是因为我把所有的JavaScript都放在HTML页面之外,放在一个特定的JS文件上。
所以此刻,当我点击按钮时,什么都没有发生。有人看到我哪里出错了吗?
HTML:
<div data-role="page" id="map" data-theme="d">
<div data-role="content">
<input type="submit" value="View Map" onclick="return mapAPI()">
<div id="map_canvas">
</div>
</div>
mapAPI函数:
function mapAPI(){
var map = new GoogleMap();
map.initialize();
}
googlemap.js:
function GoogleMap(){
this.initialize = function(){
var map = showMap();
}
var showMap = function(){
var mapOptions = {
zoom: 4,
center: new google.maps.LatLng(-33, 151),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
return map;
}
}
将事件侦听器附加到按钮。
<input type="submit" id="viewMap" value="View Map">
<script>
google.maps.event.addDomListener(document.getElementById('viewMap'), 'click', mapAPI);
</script>
你好,你在index.html的Head部分将URL列入白名单了吗。如果没有,这就是你的做法。
<meta charset="utf-8" />
<meta http-equiv="Content-Security-Policy" content="script-src 'self' https://maps.googleapis.com/ https://maps.gstatic.com/ https://mts0.googleapis.com/ 'unsafe-inline' 'unsafe-eval'">
使用Cordova 在手机上显示谷歌地图的简单方法
<script type="text/javascript">
function initialize() {
var mapOptions = {
zoom: 14,
center: new google.maps.LatLng(-33, 151),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'), mapOptions);
}
</script>
你需要API键为谷歌地图工作,生成一个并把参考头部分
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initialize" async defer></script>
相关文章:
- 使用filetransfer/cordova插件上传一些文件
- phoneGap/Cordova插件加载顺序/交易w/AdBlock
- Cordova插件在使用Framework7时不起作用
- 使用cordova插件删除iOS中应用程序的临时目录
- cordova插件屏幕方向不适用于特定页面
- Cordova 3.x插件开发
- 它是如何在cordova插件对话框中使用参数按钮Index的
- 自定义Cordova插件,释放一个保持回调而不调用它
- 哪个cordova插件可以做后台服务
- Ionic V2和Cordova插件-未捕获类型错误:无法设置属性'测试'为null
- 谷歌地图没有显示?Cordova插件
- 访问下载的html文件中的cordova插件
- 安装 Phonegap/Cordova 3.1 插件(条形码扫描仪)
- iOS 中的 Ionic 应用程序无法使用 cordova 插件媒体播放本地音频
- “流星运行安卓设备”需要永远安装Cordova插件
- “gamecenter undefined”使用Game Center Cordova插件
- 将Cordova插件与Meteor.js一起使用
- Cordova 插件 Javascript 函数调用来自 iOS 4.0.0 中的 Native
- Ionic Framework 中的 Cordova 插件媒体兼容性问题
- 从离子控制器访问cordova插件