简体   繁体   中英

Google Maps JS API Windows Phone Cordova

So i am trying to make this app that uses Google maps API. It worked with android but when i tried it on Windows Phone Emulator it says "an app can't load remote web content in the local context". Now, i searched a bit and this is to be expected (I also tried the solution that uses an iframe - didn't work.). The question is how do i fix this.Is it possible to use Google Maps with Windows Phone and Cordova and or i have to use a different Maps API?

Code that works with android but not with WP: -- Thank you All.

    <!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>

Make sure you have the right capabilities in your Manifest file. I don't do windows phpne 8 but most of the time your app needs premission from the user to have access to the internet.

Properties/WPAppManifest.xml

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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