I am currently utilizing the Bing map AJAX control in my code, which looks something like this -
function getMap()
{
map = new Microsoft.Maps.Map(document.getElementById('mnMap'), {
credentials: 'MyKey',
mapTypeId: Microsoft.Maps.MapTypeId.road
});
map.setView({
zoom: 4,
center: new Microsoft.Maps.Location(defaultLat, defaultLan)
});
Microsoft.Maps.loadModule('Microsoft.Maps.Directions', {
callback: createDirectionsManager
});
}
function createDirectionsManager()
{
if (!directionsManager)
{
directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);
}
directionsManager.resetDirections();
directionsManager.setRenderOptions({ itineraryContainer: document.getElementById('directionsPanel') });
directionsErrorEventObj = Microsoft.Maps.Events.addHandler(directionsManager, 'directionsError', displayRouteError );
directionsUpdatedEventObj = Microsoft.Maps.Events.addHandler(directionsManager, 'directionsUpdated', displayUpdatedRoute );
}
function displayUpdatedRoute(status){
// Update waypoint text inputs based on dragged markers
var legs = directionsManager.getAllWaypoints();
// Perform some validation
}
function displayRouteError(error){
// If the error is a viapoint error, display an error
if (error.responseCode == Microsoft.Maps.Directions.RouteResponseCode.noSolution){
directionsManager.resetDirections();
}else if (error.responseCode == Microsoft.Maps.Directions.RouteResponseCode.dataSourceNotFound || error.responseCode == Microsoft.Maps.Directions.RouteResponseCode.tooFar){
directionsManager.resetDirections();
}else{
directionsManager.resetDirections();
}
}
function getDirections(submit, send) {
directionsManager.resetDirections();
if (some test condition) {
start = new Microsoft.Maps.Directions.Waypoint({ location: new Microsoft.Maps.Location(locInputs.first().attr("data-lat"), locInputs.first().attr("data-lng")) });
} else {
start = new Microsoft.Maps.Directions.Waypoint({ address: locInputs.first().val() });
}
directionsManager.addWaypoint(start);
directionsManager.addWaypoint(waypoint);
directionsManager.addWaypoint(end);
directionsManager.setRenderOptions({ itineraryContainer: document.getElementById('directionsPanel') });
directionsManager.calculateDirections();
}
function saveTrip(){
var legs = directionsManager.getAllWaypoints();
// Perform some validations
// Ajax call to backend
}
$("#saveTripBtn").click(function() {
getDirections();
saveTrip();
}
Upon initialization of getMap(), I observe that the directions are correctly displayed. However, when I retrieve the waypoints using directionsManager.getAllWaypoints(), none of them contain a location object, resulting in a lack of latitude/longitude information. In the savetrip() method, I require the lat/long of each waypoint before calling the backend code, but unfortunately it is not present.
Currently, I am using a Developer key. Please let me know if any additional information is required.
Thank you in advance
Roshan