Hi,
I am working on the script that displayes the "RouteItenary" Class and whenever I implement it the map does not display. I searched for Javascript errors but there was none. How do I fix this
Hi,
I am working on the script that displayes the "RouteItenary" Class and whenever I implement it the map does not display. I searched for Javascript errors but there was none. How do I fix this
The Driving Directions script does not work.
wwwxwww
karande23
I just took your code and pasted it into Notepad. I changed both "
"s to "
" and changed the "i<len" to "i < len". Everything looks fine, and I get the route and directions on page load.
SQLServer2050
it still does not work.
Here is my script:
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="http://dev.virtualearth.net/mapcontrol/v3/mapcontrol.js"></script>
<script>
var map = null;
function GetMap()
{
map = new VEMap('myMap');
map.LoadMap();
map.GetRoute('Microsoft',
'Space Needle',
null,
null,
onGotRoute);
}
function onGotRoute(route)
{
var routeinfo="Route info:\n\n";
routeinfo+="Total distance: ";
routeinfo+= route.Itinerary.Distance+" ";
routeinfo+= route.Itinerary.DistanceUnit+"\n";
var steps="";
var len = route.Itinerary.Segments.length;
for(var i = 0; i<len ;i++)
{
steps+=route.Itinerary.Segments
steps+=route.Itinerary.Segments
steps+=route.Itinerary.DistanceUnit+"\n";
}
routeinfo+="Steps:\n"+steps;
alert(routeinfo);
}
</script>
</head>
<body onload="GetMap();">
<div id='myMap' style="position:relative; width:400px; height:400px;"></div>
</body>
</html>
Seth Livingston
lol. I see - so the solution was to change the lightbulb
John.
nate-d-o-double-g
I think your code is fine. The things I changed were likely changes that happened when you pasted your code into your post. To be concise, all three changes I made were in this section of your code:
for(var i = 0; i<len ;i++)
{
steps+=route.Itinerary.Segments.Instruction+" -- (";
steps+=route.Itinerary.Segments.Distance+") ";
steps+=route.Itinerary.DistanceUnit+"\n";
}
I changed the first line so that it reads
for (var i =0; i < len; i ++)
I changed the two lines with lightbulbs to:
steps+=route.Itinerary.Segments[ i ].Instruction (without the spaces between the brackets)
and
steps+=route.Itinerary.Segments[ i ].Distance
HemantKulkarni
Well, at least I thought it was a bright idea.
Funny how that code keeps getting changed on us. Anyway, the lightbulb that I changed was supposed to be bracket-i-bracket: [ i ] without the spaces.
spanky4_3
Thank you so much. The script works now!
I just have one more question.
How can I manipulate the
alert(routeinfo); script so that it does not appear in an alert, but something like the Mapquest layout
Sarwanan
Rraj
I'm not sure what you mean by "the MQ layout" (I don't happen to use that site...
)
But in the interactive SDK, you'll notice I pop up the directions in a translucent DIV. The only differences to this implementaiton are:
1. I formatting the routeInfo string as HTML, including replacing the /n in the code with <br> and other HTML formatting that isn't possible in an alert.
2. Create a DIV element with all the style/position stuff you want. In my case, it is hidden, yellow, 0.5 transparent, etc.
3. I set a funciton called doAlert() which sets the .innerHTML property of the DIV with the driving directions (the routeInfo variable).
4. display the DIV.