繁体   English   中英

Google Maps JS API Windows Phone Cordova

[英]Google Maps JS API Windows Phone Cordova

因此,我正在尝试制作使用Google Maps API的应用。 它适用于Android,但当我在Windows Phone模拟器上尝试它时,它说“一个应用程序无法加载本地上下文中的远程Web内容”。 现在,我搜索了一下,这是预期的(我也尝试过使用iframe的解决方案 - 没有用。)。 问题是如何解决这个问题。是否可以将谷歌地图用于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>

确保您在Manifest文件中具有正确的功能。 我不做Windows phpne 8,但大多数时候你的应用程序需要从用户预先允许访问互联网。

Properties/WPAppManifest.xml

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM