【问题标题】:Google Maps JS API Windows Phone Cordova谷歌地图 JS API Windows Phone Cordova
【发布时间】:2015-10-31 01:39:04
【问题描述】:

所以我正在尝试制作这个使用 Google 地图 API 的应用程序。它适用于 android,但是当我在 Windows Phone Emulator 上尝试它时,它说“应用程序无法在本地上下文中加载远程 Web 内容”。 现在,我搜索了一下,这是意料之中的(我也尝试了使用iframe 的解决方案 - 没有用。)。问题是我该如何解决这个问题。是否可以将 Google 地图与 Windows Phone 和 Cordova 一起使用,或者我必须使用不同的 Maps API?

适用于 android 但不适用于 WP 的代码: -- 谢谢大家。

    <!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="Content-Security-Policy" content=" ">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>BlankCordovaApp1</title>

    <!-- BlankCordovaApp1 references -->
    <link href="css/index.css" rel="stylesheet" />
    <link href="css/jquery.mobile-1.4.5.css" rel="stylesheet" />

    <script src="scripts/jquery-2.1.4.js"></script>
    <script src="scripts/jquery.mobile-1.4.5.js"></script>

    <script>
        $(document).on("pagecreate","#map-page", getMaps);

        function createMap() {
            console.log("Reached createMap() ")
            var mapOptions = {
                center: new google.maps.LatLng(37.98392, 23.71889),
                zoom: 11
            };
            var map = new google.maps.Map(document.getElementById('map'), mapOptions);
        }

        function getMaps() {
            $.getScript('http://maps.googleapis.com/maps/api/js?callback=createMap');
            console.log("Got Maps");
        }

    </script>


</head>
<body>
    <!--Page 1-->
    <div data-role="page" id="login" data-theme="b">
        <div data-role="content">
            <p>Page 1</p>
            <a href="#map-page" class="ui-btn">Page 2</a>
        </div>
    </div>

    <!--Page 2-->
    <div data-role="page" id="map-page">
        <div data-role="header">
            <h1> Header </h1>
        </div>
        <div data-role="content">
            <div id="map" style="height: 400px;width: 100%"></div>
            <a href="#" class="ui-btn" data-rel="back">Go Back</a>
        </div>
        <div data-role="footer" style="text-align:center" data-position="fixed">
            <p> Footer </p>
        </div>
    </div>

    <!-- Cordova reference, this is added to your app when it's built. -->
    <script src="cordova.js"></script>
    <script src="scripts/platformOverrides.js"></script>

    <script src="scripts/index.js"></script>
</body>
</html>

【问题讨论】:

  • 试试https://maps.googleapis.com/maps/api/js?callback=createMap
  • @user2788573 不知道您是否找到了解决此问题的方法..
  • 找到解决方案了吗?
  • 有人有解决方案吗?

标签: javascript android cordova google-maps windows-phone


【解决方案1】:

确保您的清单文件具有正确的功能。 我不使用 windows phpne 8,但大多数时候您的应用程序需要用户授权才能访问互联网。

Properties/WPAppManifest.xml

<Capabilities>
    <Capability Name="ID_CAP_NETWORKING" />
</Capabilities>

【讨论】:

  • 感谢您的回复。这已经存在于清单中。
猜你喜欢
  • 2016-04-16
  • 1970-01-01
  • 2020-05-15
  • 2017-12-11
  • 2011-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多