【问题标题】:google maps is not show in cordova android, but show in browser谷歌地图不在cordova android中显示,但在浏览器中显示
【发布时间】:2016-10-09 17:17:51
【问题描述】:

你好,我是科尔多瓦和谷歌地图的新手,我在科尔多瓦项目中构建了简单的谷歌地图。我的代码在浏览器中正常工作,但是当我内置 apk 并安装在设备中时,谷歌地图不显示。

index.html

<!DOCTYPE html>

<html>
   <head>
    <meta http-equiv="Content-Security-Policy" content="default-src 'self' data gap  https://*.google.com  https://*.googleapis.com  https://*.gstatic.com  https://*.googleusercontent.com 'unsafe-inline' 'unsafe-eval'; media-src *">
    <meta name="format-detection" content="telephone=no">
    <meta name="msapplication-tap-highlight" content="no">
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
    <link rel="stylesheet" type="text/css" href="css/index.css">
    <title>Hello World</title>
    <style>
  html, body {
    height: 100%;
    margin: 0;
    padding: 0;
  }
  #map {
    height: 100%;
  }
</style>
</head>
<body>
    <div id="map">Maps</div>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
     <script src="https://maps.googleapis.com/maps/api/js?key=xxxxxxxxxxxxxxxxxxxx&callback=initMap"
    async defer></script> 
</body>

index.js

 var map;
  function initMap() {
    map = new google.maps.Map(document.getElementById('map'), {
      center: {lat: -34.397, lng: 150.644},
      zoom: 8
    });
  }

有什么问题?

【问题讨论】:

标签: javascript android cordova google-maps


【解决方案1】:

尝试像这样运行它。测试seTimeout,也许你不需要这个.. 我希望这会对你有所帮助。

function loadScript() {
              var script = document.createElement("script");
              script.src = "http://maps.googleapis.com/maps/api/js?callback=initMap";
              document.body.appendChild(script);
            }
            setTimeout(function(){ loadScript() }, 1000);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-28
    • 1970-01-01
    • 2017-03-07
    • 2013-08-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多