none
Bing maps Directions Manager RRS feed

  • Question

  • Actually,the Bing API for displaying routes "  directionsManager.calculateDirections()" does not seem to be working. No error shows up on debugging. What could be the reason for it?

    It's urgent . Please help.

    function getMapForDefaultRoute() {
            //retrieveTripLocations();
            // Initialize the map
           
            mapDefault = new Microsoft.Maps.Map(document.getElementById("mapDiv"), { credentials: "BING_MAPS_KEY", mapTypeId: Microsoft.Maps.MapTypeId.road, zoom: 2 });
           
            retrieveLocationsForWaypointsOnRoute();
            Microsoft.Maps.loadModule('Microsoft.Maps.Directions', { callback: directionsModuleLoaded });



        }

        function directionsModuleLoaded() {
            // Initialize the DirectionsManager
            var directionsManager = new Microsoft.Maps.Directions.DirectionsManager(mapDefault);
            //retrieveTripLocations();
            // Create start and end waypoints
            for (latitudeIndex = 0; latitudeIndex < pinCount; latitudeIndex++) {
                longitudeIndex = 0;
                waypoints[latitudeIndex] = new Microsoft.Maps.Directions.Waypoint({ address: myCities[latitudeIndex], location: new Microsoft.Maps.Location(latitudeLongitudeCollection[latitudeIndex][longitudeIndex], latitudeLongitudeCollection[latitudeIndex][++longitudeIndex]) });
                //longitudeIndex++;
            }

            //var startWaypoint = new Microsoft.Maps.Directions.Waypoint({ address: myCities[0] });
            //var Waypoint1 = new Microsoft.Maps.Directions.Waypoint({ address: myCities[1] });
            //var Waypoint2 = new Microsoft.Maps.Directions.Waypoint({ address: myCities[2] });
            //var endWaypoint = new Microsoft.Maps.Directions.Waypoint({ address: myCities[3] });
            //var Waypoint3 = new Microsoft.Maps.Directions.Waypoint({ address: myCities[4] });


            for (i = 0; i < pinCount; i++) {
                directionsManager.addWaypoint(waypoints[i]);
            }

            //directionsManager.addWaypoint(startWaypoint);
            //directionsManager.addWaypoint(Waypoint1);
            //directionsManager.addWaypoint(Waypoint2);
            //directionsManager.addWaypoint(endWaypoint);
            //directionsManager.addWaypoint(Waypoint3);

            // Set the id of the div to use to display the directions
            directionsManager.setRenderOptions({ itineraryContainer: document.getElementById('itineraryDiv') });

            // 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) {
            alert(e.message);
        }

       

        function retrieveLocationsForWaypointsOnRoute() {
            ///<summary>
            /// This function is passed through the request and is iterated for each page of data
            /// This function appends rows to the accountsGrid.
            ///</summary>
           

            for (i = 0; i < pinCount; i++) {

               
                myCities[i] = pinCollection[i][2];
               
                longitudeIndex = 0;
                latitudeLongitudeCollection[i] = new Array(2);
                latitudeLongitudeCollection[i][longitudeIndex] = pinCollection[i][6];
                longitudeIndex++;
                latitudeLongitudeCollection[i][longitudeIndex] = pinCollection[i][7];

            }
        }

            

    anwesha


    • Edited by Ricky_Brundritt Monday, October 1, 2012 1:28 PM Removing Bing Maps Key
    Monday, October 1, 2012 11:08 AM

Answers

All replies

  • To add to this, i am getting an error "window.location.search" is null or undefined when i debug "directionsManager.calculateDirections()". May be this is the reason the route is not showing.


    anwesha

    Tuesday, October 2, 2012 7:04 AM
  • It is working in ISDK, so seems issue specific to implementation. Could you compare your code with one in www.bingmapsportal.com/ISDK/AjaxV7#DirectionsModule2 ?

    One more thing, it requires valid credentials, so I assume you are passing credetials as well.


    MSFT
    Hemant Goyal

    Tuesday, October 2, 2012 4:39 PM