简体   繁体   English

Bing Maps API在PC上有效,但不适用于移动Web应用程序

[英]Bing maps api works on pc but not mobile web app

I really hope someone can help with my problem. 我真的希望有人可以帮助解决我的问题。 I have built a mobile web app http://ufa-ld-qa.azurewebsites.net/ (the QA site) with asp.net mvc4 using Bing Maps API for various functionality in the app. 我使用Bing Maps API使用asp.net mvc4构建了一个移动网络应用程序http://ufa-ld-qa.azurewebsites.net/ (质量检查网站),该应用程序具有多种功能。 I am having problems with the directions module. 我在Directions模块中遇到问题。 When I view the site on my pc (Chrome and IE) it works fine and I see no errors but on mobile devices it is not working (but it did work fine yesterday when we launched to QA). 当我在我的PC(Chrome和IE)上查看该网站时,它可以正常工作,并且看不到任何错误,但在移动设备上却无法正常工作(但昨天在我们开始进行质量检查时,它确实可以正常工作)。 I have used HTML5 geolocation (this may be the issue) to get user's location to allow them to get directions to a location. 我已经使用HTML5地理位置(这可能是问题)来获取用户的位置,以允许他们获取到某个位置的路线。 I will post my code below and if anyone could please help me it would be greatly appreciated. 我将在下面发布我的代码,如果有人可以帮助我,将不胜感激。 We have tested it on about 7 different mobile devices with different OS's and it doesn't work on any. 我们已经在大约7种具有不同操作系统的不同移动设备上对其进行了测试,并且无法在任何设备上运行。 Does anyone know if this is a Bing issue or my code below? 有人知道这是Bing还是我的下面的代码? Thanks so much in advance. 非常感谢。

<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>

A couple of things to try. 有几件事可以尝试。 First ensure that your app is allowed to access the users location. 首先,请确保您的应用被允许访问用户位置。 Most mobile platforms require you to mark that the app requires access to the GPS in the manifest. 大多数移动平台都要求您标记该应用程序需要访问清单中的GPS。 Another thing to look into is the possibility that the userLocation isn't populated before your callback for the directions manager is called. 要注意的另一件事是在调用路线管理器的回调之前未填充userLocation的可能性。 It's possible that the GPS takes a little longer on the mobile device to find the users location and as such the directions loaded function is firing before the users location is set, thus passing in a null starting . GPS可能需要在移动设备上花费更长的时间才能找到用户位置,因此在设置用户位置之前会触发加载方向的功能,从而传递null值。 You might find it useful to have a flag to indicate that the directions manager has loaded and a simple function that runs after setting the flag and also runs after setting the use location that checks that both the directions manager has loaded and the user location has been set and then calls your directions loaded function. 您可能会发现,有一个标记来指示方向管理器已加载,并且一个简单的函数在设置该标志后运行,并在设置使用位置后运行(该功能会检查方向管理器是否已加载且用户位置已被定位),这会很有用。设置,然后调用您的路线加载功能。

My Windows Phone 8 App is experiencing similar behavior. 我的Windows Phone 8应用程序遇到类似的行为。 (Nokia 920) (诺基亚920)

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

When the Website preference is set to 'desktop version' the map renders correctly . 当“网站”偏好设置设置为“桌面版本”时,地图将正确呈现。

When the Website preference is set to 'mobile version' the map renders incorrectly . 当“网站”偏好设置设置为“移动版本”时,地图显示不正确

Just started happening about a week ago ! 大约一周前才开始发生!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM