混合应用中的Bing地图 [英] Bing Maps in a hybrid app

查看:226
本文介绍了混合应用中的Bing地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正尝试在Visual Studio中提供的新的多设备混合应用程序模板中使用Bing Maps AJAX API v7,该模板使用Apache Cordova提供跨平台兼容性。我编写了以下代码,遵循模板 http://msdn.microsoft.com/en-us/library/gg427624。 aspx

I am currently trying to use the Bing Maps AJAX API v7 in the new 'Multi-device hybrid App" template provided in Visual Studio, which uses Apache Cordova to provide crossplatform compatibility. I have written the following code, following the template at http://msdn.microsoft.com/en-us/library/gg427624.aspx :

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<head>
    <meta charset="utf-8" />
    <title>Wand</title>

    <!-- Wand references -->
    <link href="css/index.css" rel="stylesheet" />

    <script charset="UTF-8" type="text/javascript" src="https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0&s=1">
    </script>

    <script type="text/javascript">

    function GetMap() {
        var map = new Microsoft.Maps.Map(document.getElementById("map"), { credentials: "AgegeewHkb9iTTQDLseMTuQyxQyZybs7uUv7aqIgKu6U8CiaflVNApy5WtDXqtHr " });
    }

    </script>

</head>
<body onload="GetMap();">

    <div id='map' class="mainview"></div>
    <div class="menu">This is the menu</div>
    <!-- Cordova reference, this is added to your app when it's built. -->
    <script src="cordova.js"></script>

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



</body>
</html>

但是当我在Windows 8.1中调试时,它说Microsoft没有定义)。我假设图书馆来自

But when I debug it in Windows 8.1, it says that Microsoft is not defined (in the GetMap function). I asume that the library from

https:// ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0&s=1

https:// ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0&s=1

尚未正确载入。我的代码有什么问题吗?我应该使用AJAX WEB API,还是有另一个应用程序(我看到的只有一个是为Windows 8)?

has not been loaded properly. Is there anything wrong with my code? Should I use the AJAX WEB API, or is there another for apps (the only one I have seen is for Windows 8 only)?

我认为我的应用程序无法加载网络库,因为它没有正确的权限。在config.xml中有一个域访问部分,但它说它不适用于Windows平台,那么如何设置它允许加载页面从https:// ecn.dev.virtualearth.net?

I think that my app is unable to load the web library because it doesn't have the proper permisions. In the config.xml there is a domain access section, but it says it doesn't appy to the windows platform, so how can I set it to allow loading pages from https:// ecn.dev.virtualearth.net ?

编辑:从Web上下文(ms-appx-web)加载脚本使脚本运行,但如果我想代码是多平台,我不能使用它。解决方案是在Windows 8清单中包含Bing地图URL的权限,我该如何做?

Loading the script from a Web context (ms-appx-web) makes the script run, but if I want the code to be multiplatform I cannot use it. The solution would be to include in the Windows 8 manifest a permission for the Bing maps URL, how can I do it?

推荐答案



INDEX.HTML




INDEX.HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <meta charset="utf-8" />
    <title>Cordova Bing Mapping</title>

    <link href="css/index.css" rel="stylesheet" />

    <!--Needed for iOS & Android-->
    <script charset="UTF-8" type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
</head>
<body>
    <div id='map' class="mainview"></div>
    <div class="menu">This is the menu</div>
    <!-- Cordova reference, this is added to your app when it's built. -->
    <script src="cordova.js"></script>
    <script src="scripts/index.js"></script>
</body>





INDEX.JS



INDEX.JS

(function () {
    "use strict";

    document.addEventListener( 'deviceready', onDeviceReady.bind( this ), false );

    //Loads Scripts Dynamically
    function loadScript(filename) {
        var fileref = document.createElement('script')
        fileref.setAttribute("type", "text/javascript")
        fileref.setAttribute("src", filename)
    }

    function onDeviceReady() {

        // Load Local Scripts if Windows
        if (device.platform == "windows") {
            MSApp.execUnsafeLocalFunction(
            function () {
                loadScript("scripts/veapicore.js");  //Bing Maps SDK VS 2013
                loadScript("scripts/veapiModules.js"); //Bing Maps SDK VS 2013
                loadScript("scripts/mapcontrol.js"); //downloaded from http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0

                Microsoft.Maps.loadModule("Microsoft.Maps.Map", {
                    callback: loadMap
                });
            })
        }

    };

    function loadMap() {
        var map = new Microsoft.Maps.Map(document.getElementById("map"), {
            credentials: "BING_MAPS_KEY"
        });
    }
})();






注意




NOTES


* This will work on Windows 8, Windows Phone 8, iOS, Android
* Bing Maps SDK VS 2013
  1. Download Location: https://visualstudiogallery.msdn.microsoft.com/224eb93a-ebc4-46ba-9be7-90ee777ad9e1 
  2. Local Location: C:\Users\[USER]\AppData\Local\Microsoft SDKs\Windows\v8.1\ExtensionSDKs\Bing.Maps.JavaScript\1.313.0825.1\redist\commonconfiguration\neutral\Bing.Maps.JavaScript\
* For Windows Phone (Universal) - Microsoft.Maps.loadModule("Microsoft.Maps.Map", { callback: loadMap }); is still undefined.

这篇关于混合应用中的Bing地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆