【问题标题】:Bing maps api works on pc but not mobile web app必应地图 api 适用于 PC,但不适用于移动 Web 应用
【发布时间】:2013-08-21 22:12:47
【问题描述】:

我真的希望有人可以帮助解决我的问题。我使用 Bing Maps API 构建了一个带有 asp.net mvc4 的移动网络应用程序http://ufa-ld-qa.azurewebsites.net/(QA 站点),以实现应用程序中的各种功能。我在使用方向模块时遇到问题。当我在我的电脑(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>

【问题讨论】:

    标签: javascript html geolocation bing-maps


    【解决方案1】:

    有几件事可以尝试。首先确保允许您的应用访问用户位置。大多数移动平台要求您在清单中标记应用程序需要访问 GPS。要研究的另一件事是在调用方向管理器的回调之前未填充 userLocation 的可能性。移动设备上的 GPS 可能需要更长的时间才能找到用户的位置,因此在设置用户位置之前会触发加载的方向功能,因此传入 null 开始。您可能会发现有一个标志来指示路线管理器已加载以及一个简单的函数在设置标志后运行并在设置使用位置后运行以检查路线管理器是否已加载以及用户位置是否已加载,这很有用设置,然后调用您的路线加载函数。

    【讨论】:

      【解决方案2】:

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

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

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

      当网站偏好设置为“移动版”时,地图会错误地呈现

      大约一周前才开始发生!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-01-21
        • 1970-01-01
        • 1970-01-01
        • 2018-09-17
        • 2021-05-24
        • 2016-12-14
        • 1970-01-01
        相关资源
        最近更新 更多