我真的希望有人可以帮助解决我的问题。我已经构建了一个移动网络应用程序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>