windows phone 8.1

时间:2016-04-17 08:22:27

标签: javascript windows-phone-8.1 bing-maps

我正在开发一个使用地图的应用程序,并且正在使用html,javascript进行开发,我发现Windows商店应用程序有一个扩展用于使用bing地图,但它不支持windows phone 8.1 javascript app开发。所以我入侵了RT的entension并添加到我的项目中,只有我得到的错误是Windows.ApplicationModel.Resource.core.ResourceManager已被弃用。我知道其他脚本在地图之前加载。而且我仍然无法找到解决方案。这是我的代码。

default.html中

    <!DOCTYPE html>
    <html>
     <head>
       <meta charset="utf-8" />
        <title>homePage</title>

<!-- WinJS references -->
<script src="//Microsoft.Phone.WinJS.2.1/js/base.js"></script>
<script src="//Microsoft.Phone.WinJS.2.1/js/ui.js"></script>

<link href="/css/default.css" rel="stylesheet" />
<link href="/pages/home/home.css" rel="stylesheet" />
<script src="/pages/home/home.js"></script>

<!-- bing map api-->
<script type="text/javascript" src="/js/bing/veapicore.js"></script>
<script type="text/javascript" src="/js/bing/veapiModules.js"></script>
<link href="/css/mapcontrol.css" rel="stylesheet" />

<!--<script type="text/javascript"
        src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0">
</script>-->

<!-- bing map controls-->
<script src="/js/MapControls.js"></script>
 </head>
<body>
<!-- The content that will be loaded and displayed. -->
<div class="fragment homepage">
    <header aria-label="Header content" role="banner">
        <h1 class="titlearea win-type-ellipsis">
            <span class="pagetitle">Native</span>
        </h1>
    </header>
    <section aria-label="Main content" role="main" style="overflow:auto;">
        <div style="float:left; margin: 10px 10px 10px 10px;">
            <input type="button" value="Get My Location" onclick="GetMyLocation();" />
            <input type="text" id="txtStart" placeholder="Source" maxlength="50" />
            <input type="text" id="txtEnd" placeholder="Destination" maxlength="50" />
            <input type="button" value="Create Route" onclick="GetRoute();" />
        </div>
       <div id="mapcontainer" style="height:150px;width:150px;"></div>
       <div id='itineraryDiv' style="position:relative; width:40%; height:90%; float: right; overflow:auto; font-family:Verdana, Arial"></div> 
    </section>
</div>

   

mapcontrol.js

    (function () {
     function initialize() {
      Microsoft.Maps.loadModule('Microsoft.Maps.Map', { callback: GetMap });
     }
      document.addEventListener("DOMContentLoaded", initialize, false);
     })();


      var map, searchManager, directionsManager, loc = null;

      function GetMap() {
       var mapOptions =
       {
        credentials: "bing map key",
        mapTypeId: Microsoft.Maps.MapTypeId.road
       };
       map = new Microsoft.Maps.Map(document.getElementById("mapcontainer"),       mapOptions);
        }

        function GetMyLocation() {
           var geolocator = new Windows.Devices.Geolocation.Geolocator();
           geolocator.getGeopositionAsync().then(function (loc) {
           var mapCenter = map.getCenter();
           mapCenter.latitude = loc.coordinate.latitude;
           mapCenter.longitude = loc.coordinate.longitude;
           map.setView({ center: mapCenter, zoom: 12 });

            var loc = new Microsoft.Maps.Location(loc.coordinate.latitude, loc.coordinate.longitude);
            var pushPin = new Microsoft.Maps.Pushpin(loc);
            map.entities.push(pushPin);
           });  
          }

       function geocodeCallback(response, userData) {
          if (response &&
               response.results &&
             response.results.length > 0) {
             var r = response.results[0];
             var l = new Microsoft.Maps.Location(r.location.latitude,                  r.location.longitude);

    //Display result on map       
    var p = new Microsoft.Maps.Pushpin(l);
    map.entities.push(p);

    //Zoom to result
    map.setView({ center: l, zoom: 15 });
     } else {
    ShowMessage("Geocode Response", "Not results found.");
     }
    }

    function GetRoute() {
     ClearMap();

    if (directionsManager) {
       directionsManager.setRequestOptions({ routeMode:    Microsoft.Maps.Directions.RouteMode.driving });

    var startWaypoint = new Microsoft.Maps.Directions.Waypoint(
        { address: document.getElementById('txtStart').value });

    var endWaypoint = new Microsoft.Maps.Directions.Waypoint(
        { address: document.getElementById('txtEnd').value });

    directionsManager.addWaypoint(startWaypoint);
    directionsManager.addWaypoint(endWaypoint);

    directionsManager.setRenderOptions({ itineraryContainer:   document.getElementById('itineraryDiv') });
    directionsManager.calculateDirections();
} else {
    Microsoft.Maps.loadModule('Microsoft.Maps.Directions', {
        callback: function () {
            directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);

            GetRoute();
            }
        });
     }
 }

   function ClearMap() {
      map.entities.clear();

      if (directionsManager) {
       directionsManager.resetDirections();
     }
    }

   function geocodeError(request) {
    ShowMessage("Geocode Error", "Unable to Geocode request.");
}

  function ShowMessage(title, msg) {
     var m = new Windows.UI.Popups.MessageDialog(title, msg);
    m.showAsync();
 }

我得到的错误是。

不推荐使用Windows.ApplicationModel.Resources.Core.ResourceManager.get_DefaultContext方法。在Windows Phone&#39; OSVersion&#39;之后,DefaultContext可能会被更改或不可用于发布。 (TBD)。而是使用ResourceContext.GetForCurrentView。

如果有人弄清楚它会很有帮助。提前谢谢。

1 个答案:

答案 0 :(得分:0)

使用Bing Maps V7或v8的在线URL,而不是Windows 8 API中的JS文件。请注意,Windows 8中不推荐使用Windows 8 API。