簡體   English   中英

Windows Phone 8.1中的必應地圖

[英]bing maps in windows phone 8.1

我正在開發一個使用地圖的應用程序,並且正在使用html,javascript進行開發,我發現Windows商店應用程序有一個擴展以使用必應地圖,但是Windows Phone 8.1 javascript應用程序開發不支持該擴展。 所以我侵入了RT擴展並將其添加到我的項目中,但我得到的唯一錯誤是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'OSVersion'(TBD)之后的發行版中,DefaultContext可能會更改或不可用。 而是使用ResourceContext.GetForCurrentView。

如果有人弄清楚,它將非常有幫助。 提前致謝。

使用Bing Maps V7或v8的在線URL,而不使用Windows 8 API中的JS文件。 請注意,Windows 10不推薦使用Windows 8 API。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM