基于Bing Maps Web Control API规划路线时能否忽略交通状况?
Great question! Yes, you absolutely can configure the Bing Maps Web Control API to ignore real-time traffic conditions—including temporary road closures—while still offering users route options based on highway/non-highway preferences. Let’s break down how to implement this:
1. Disable Traffic Usage
The core setting to bypass real-time traffic data is the trafficUsage parameter in your route request options. Setting this to disabled tells the API to calculate routes using only the static base road network, ignoring all live disruptions like temporary closures, accidents, or congestion.
2. Define Route Type Preferences
To retain highway/non-highway route options for users, use the routeType property. You can pass an array of route profiles here to offer choices like fastest (highway-focused), shortest, or scenic (non-highway prioritized).
Example Implementation Code
Here’s a practical code snippet showing how to set this up:
// Initialize your map const map = new Microsoft.Maps.Map('#mapContainer', { credentials: 'YOUR_BING_MAPS_API_KEY' }); // Create a Directions Manager instance const directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map); // Configure route request options directionsManager.setRequestOptions({ // Disable traffic entirely trafficUsage: Microsoft.Maps.Directions.TrafficUsage.disabled, // Offer multiple route types (adjust based on your needs) routeType: [ Microsoft.Maps.Directions.RouteType.fastest, Microsoft.Maps.Directions.RouteType.shortest, Microsoft.Maps.Directions.RouteType.scenic ] }); // Add origin and destination waypoints const origin = new Microsoft.Maps.Directions.Waypoint({ address: 'New York, NY' }); const destination = new Microsoft.Maps.Directions.Waypoint({ address: 'Boston, MA' }); directionsManager.addWaypoint(origin); directionsManager.addWaypoint(destination); // Trigger route calculation directionsManager.calculateDirections();
Key Notes to Remember
- When
trafficUsageis set todisabled, the API won’t factor in any real-time road changes—routes will strictly follow the static road layout. - The
routeTypearray lets you present users with distinct route options. For non-highway routes,scenicis a great choice if you want to prioritize local roads over interstates. - Ensure your Bing Maps API key has the necessary permissions for the Directions service (most standard keys include this by default).
内容的提问来源于stack exchange,提问作者Michael Witt

