chathun chathun - 1 year ago 141
PHP Question

how to draw driving route path using two point latitude and longitude

i need know how to draw driving route between two locations(pushpin) using latitude and longitude in this locations.i know how to draw two locations driving route using location names.need use latitude and longitude for this. is it possible ? (in bing map )

enter image description here

Answer Source

Yeah, it's possible. Try the below code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
      <script type="text/javascript" src=""></script>
      <script type="text/javascript">

         var map = null;
         var directionsManager = null;

         function GetMap() {
            // Initialize the map
            map = new Microsoft.Maps.Map(document.getElementById("mapDiv"),{credentials:"Your Bing Map Key"});
            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:new Microsoft.Maps.Location(33.993065, -117.918015)}); 
            var endWaypoint = new Microsoft.Maps.Directions.Waypoint({location:new Microsoft.Maps.Location(42.28695, -71.59419)} );


            // Set request options
            directionsManager.setRequestOptions({ avoidTraffic: true, maxRoutes: 1 });

            // Set the render options
            directionsManager.setRenderOptions({ itineraryContainer: document.getElementById('itineraryDiv'), 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

         function displayError(e) {
            // Display the error message

   <body onload="GetMap();">
      <div id='mapDiv' style="position:relative; width:600px; height:600px;"></div>       
      <div id='itineraryDiv' style="position:relative; width:400px;"></div>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download