Hi guys,
I'm trying to return directions in kilometres and the current code works fine when the user enters a disambiguous location, but, when an ambiguous location is entered and the user selects one from the subsequent list of possible locations, the corresponding directions returned and in miles.
It seems like the handler for ambiguous locations doesn't remember the parameter for unit of measurement that I specified in the original map.GetRoute call - is this a bug or have I not set a parameter that I'm supposed to
For an example of directions in Miles, mouse over one of the pushpins and type in "Sydney" - then from the list of possible locations, select "Sydney, New South Wales, Australia".
To see the directions returned in Kilometres, type in a disambiguous location - "Sydney, New South Wales, Australia".
For a related problem also, feel free to check out my other thread:
http://forums.microsoft.com/msdn/ShowPost.aspx postid=1467804&siteid=1
Here's the code in full
-----------------
<!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><
html> <head> <title>Testing maps 7</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script src="http://dev.virtualearth.net/mapcontrol/v4/mapcontrol.js"></script> <script type="text/javascript">
var map = null; var origin = ''; //Stores origin/postcode from user for subsequent reuse (useability requirement) var locs = new Array; var safeMode = false; // Flag determines if map should load in "safemode" function GetMap()
{
map =
new VEMap('myMap'); try{
map.LoadMap();
map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
}
catch (err){
safeMode=
true;}
RefreshPushpins();
map.SetMapView(locs);
}
function BuildPushpin(index, title, href, address){
if(safeMode){
// Display pushpins (so not a TRUE safemode, but its userfriendly) but turn off "directions" functionality -- as of 29/03/2007 VE doesn't support FF 2.0 return new VEPushpin(index, locs[index], 'pushpinleaf.gif', '<a href="'+href+'">'+title+'</a>', address, 'VEmap_iconStyle','VEmap_titleStyle','VEmap_detailsStyle');}
else{
return new VEPushpin(index, locs[index], 'pushpinleaf.gif', '<a href="'+href+'">'+title+'</a>', address+'<div class="originDiv"><span class="originTitle">Get me there:</span>From: <input type="text" class="originTextBox" id="origin'+index+'" value="'+origin+'" title="e.g. \'2000\' (postcode for Sydney, NSW, Australia)"/><input type="submit" class="originButton" id="submitOrigin'+index+'" value="Get Directions" onclick="GetJourney(\'origin'+index+'\','+index+');" /></div>', 'VEmap_iconStyle','VEmap_titleStyle','VEmap_detailsStyle');}
}
function RefreshPushpins(){
map.DeleteAllPushpins();
locs =
new Array; var loc = new VELatLong(-38.36460840347736, 144.94005203247073); locs.push(loc); var pin = BuildPushpin(0, 'Mornington Peninsula', '/article.aspx id=147335', ''); map.AddPushpin(pin); var loc = new VELatLong(-38.40285712900175, 144.84302043914795); locs.push(loc); var pin = BuildPushpin(1, 'Peninsula Hot Springs', '/article.aspx id=147336', 'Springs Lane, Rye, Vic'); map.AddPushpin(pin); var loc = new VELatLong(-38.21301302274773, 145.03319978713986); locs.push(loc); var pin = BuildPushpin(2, 'Relax, Go Fishing!', '/article.aspx id=147338', 'Mornington Pier, Schnapper Point Drive, Mornington, Vic'); map.AddPushpin(pin); var loc = new VELatLong(-38.49185752765312, 144.88790988922122); locs.push(loc); var pin = BuildPushpin(3, 'Cape Schanck Lighthouse', '/article.aspx id=147339', '420 Cape Schanck Rd, Cape Schanck, Vic'); map.AddPushpin(pin); var loc = new VELatLong(-37.14116138236253, 142.51893997192386); locs.push(loc); var pin = BuildPushpin(4, 'Grampians Personalised Tours & Adventures', 'http://www.grampianstours.com" target="new', 'Main St, Halls Gap, Vic'); map.AddPushpin(pin); var loc = new VELatLong(-37.64984951217565, 142.34556198120114); locs.push(loc); var pin = BuildPushpin(5, 'Aquila Eco Lodges', '/article.aspx id=147340', 'Near Dunkeld, Vic'); map.AddPushpin(pin);}
function GetJourney(originID, indexDestination){
//save it to 'origin' only if it's different and then refresh if (document.getElementById(originID).value != ''){
if (origin != document.getElementById(originID).value){
origin = document.getElementById(originID).value;
RefreshPushpins();
}
map.GetRoute(origin, locs[indexDestination], VEDistanceUnit.Kilometers,
null, onGotRoute);}
}
function onGotRoute(route){
var routeinfo="<h2>Directions:</h2>";routeinfo+=
"<span id=\"totalDistance\">Total distance: ";routeinfo+= route.Itinerary.Distance+
" ";routeinfo+= route.Itinerary.DistanceUnit+
"</span>"; var steps=""; var len = route.Itinerary.Segments.length; for(var i = 0; i < len ;i++){
steps+=
"<li>"+route.Itinerary.Segments[i].Instruction+" -- (";steps+=route.Itinerary.Segments[i].Distance+
") ";steps+=route.Itinerary.DistanceUnit+
"</li>";}
routeinfo+=
"<ol>"+steps;+"</ol>";document.getElementById(
"directions").innerHTML = routeinfo;}
window.onload=GetMap;
</script><style type="text/css"> #VEContainer { position: relative; font-size: 11px; font-family: verdana, arial; width: 600px;
}
#myMap { margin-top: 20px; margin-left: 10px; width: 600px; height: 600px; border:#555555 2px solid; position:relative;}
.VEmap_titleStyle{
font-family:Arial; font-size:12px;}
.VEmap_detailsStyle{
font-family:Arial; font-size:12px;}
#directions { margin:10px;}
#buttons { margin-left: 10px; margin-top: 15px; float: right;}
#buttons #close { margin-left: 10px;}
.originDiv{
height:100%; vertical-align:bottom; width:100%; margin-top:20px; border-top:1px solid #999; font-family:Arial; font-size:12px;}
.originTitle{
font-family:Arial; font-size:12px; font-weight:bold; margin-top:5px; margin-bottom:15px; display:block; width:100%;}
.originTextBox{ font-family:Arial; font-size:12px; width:90px;}
.originButton{ width:90px; font-family:Arial; font-size:12px;}
</style> </head> <body> <div id="VEContainer"> <div id="myMap"></div> <div id="directions"></div> <div id="buttons"><a href="javascript:window.print();" id="print">Print</a><a href="javascript:self.close();" id="close">Close</a></div> </div> </body>
</
html>