1

我真的希望有人可以帮助解决我的问题。我已经构建了一个移动网络应用程序http://ufa-ld-qa.azurewebsites.net/(QA 站点)与 asp.net mvc4 使用 Bing Maps API 在应用程序中实现各种功能。我在使用方向模块时遇到问题。当我在我的电脑(Chrome 和 IE)上查看该网站时,它运行良好,我没有看到任何错误,但在移动设备上它无法运行(但昨天我们启动 QA 时它确实运行良好)。我已经使用 HTML5 地理位置(这可能是问题)来获取用户的位置,以允许他们获取到某个位置的路线。我将在下面发布我的代码,如果有人可以帮助我,将不胜感激。我们已经在大约 7 种具有不同操作系统的不同移动设备上对其进行了测试,但它无法在任何设备上运行。有谁知道这是 Bing 问题还是我下面的代码?提前非常感谢。

<script type="text/javascript">
    var map = null;
    var directionsManager = null;
    var userLat = null;
    var userLong = null;
    var userPosition = null;
    var latlng = new Microsoft.Maps.Location(@Model.latitude, @Model.longitude);
    navigator.geolocation.getCurrentPosition(locationHandler);

    function locationHandler(position)
    {

        userPosition = new Microsoft.Maps.Location(position.coords.latitude, position.coords.longitude);
    }  
    function GetMap() {

        // Initialize the map
        map = new Microsoft.Maps.Map(document.getElementById("map"), { credentials: "Au_7giL-8dUbFkJ8zLjcQKy4dV2ftPfpMxQ0_sVBksoj4Y-1nBT00Z1oqUIU894_",
            mapTypeId: Microsoft.Maps.MapTypeId.road});
        Microsoft.Maps.loadModule('Microsoft.Maps.Directions', { callback: directionsModuleLoaded });


    }
        function directionsModuleLoaded() {
            // Initialize the DirectionsManager
            directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);

            // Create start and end waypoints
            var startWaypoint = new Microsoft.Maps.Directions.Waypoint({ location: userPosition });
            var endWaypoint = new Microsoft.Maps.Directions.Waypoint({ location: latlng });

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


            // Set request options
            directionsManager.setRequestOptions({ routeMode: Microsoft.Maps.Directions.RouteMode.driving });

            // Set the render options
            directionsManager.setRenderOptions({ 
                itineraryContainer: document.getElementById('directionPanel'), 
                displayWalkingWarning: false, 
                walkingPolylineOptions: { strokeColor: new Microsoft.Maps.Color(200, 0, 255, 0) },
                });


            // Specify a handler for when an error occurs
            Microsoft.Maps.Events.addHandler(directionsManager, 'directionsError', displayError);

            // Calculate directions, which displays a route on the map
            directionsManager.calculateDirections();



        } 

        function displayError(e) {
            // Display the error message
            alert(e.message);


        }




      </script>
4

2 回答 2

1

有几件事要尝试。首先确保允许您的应用访问用户位置。大多数移动平台都要求您在清单中标记应用程序需要访问 GPS。要研究的另一件事是在调用方向管理器的回调之前未填充 userLocation 的可能性。移动设备上的 GPS 可能需要更长的时间才能找到用户的位置,因此在设置用户位置之前会触发加载的方向功能,因此传入 null 开始。

于 2013-08-29T12:39:51.047 回答
0

我的 Windows Phone 8 应用程序遇到了类似的行为。(诺基亚 920)

http://bing.com/maps/default.aspx?cp=47.677797~-122.122013&lvl=12

当网站首选项设置为“桌面版本”时,地图会正确呈现。

当网站首选项设置为“移动版”时,地图呈现不正确

大约一周前才开始发生!

于 2013-08-28T23:46:21.630 回答