allann


Hi, i seem to be having an issue with map.getroute() in IE7. when i submit a request for directions to say:

manchester to london it works fine, but if i then submit a request to newcastle to london the request is processed as if i am asking for directions from newcastle to newcastle. however this problem does not occur in firefox.

The code i am using is as follows:

function GetDirections()

{

map = new VEMap('myMap');

map.LoadMap();

map.GetRoute(document.getElementById('txtFrom').value,document.getElementById('txtTo').value,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 it = 0; i < len ;it++)

{

steps+=route.Itinerary.Segments[it].Instruction+" -- (";

steps+=route.Itinerary.Segments[it].Distance+") ";

steps+=route.Itinerary.DistanceUnit+"\n";

}

routeinfo+="Steps:\n"+steps;

document.getElementById('txtDirections').value = routeinfo;

}

Thanks.




Re: issue with getroute() ie7

Richard_Brundritt


That's odd. I just tried it and it worked. If you are specifying a more detailed location than just Newcastle it is possible that the starting location is trapped by a one-way street. This occurs with some addresses when routing.





Re: issue with getroute() ie7

allann

thanks for the reply, but that is not the problem as no matter which two locations i enter on the second request it will assume i want directions to 'newcastle' from 'newcastle' for example.

Did you have to alter any of the code to make it work on your page






Re: issue with getroute() ie7

Richard_Brundritt

I did replace the getDocument stuff with strings, "Newcastle" and "London"




Re: issue with getroute() ie7

Bryan Higgins

Can you post the HTML for your form I suspect that you might have two elements with the same ID. Firefox's implementation of getElementByID works a bit differently than IE's implementation.





Re: issue with getroute() ie7

allann

Hi, the textboxes are referenced fine because it works correctly the first time a request is made it only fails when you make a second request in ie7.

below is a copy of the page.

<html>
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
<script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx v=5"></script>
<script>

function GetDirections()
{
map = new VEMap('myMap');
map.LoadMap();
map.GetRoute(document.getElementById('txtFrom').value,document.getElementById('txtTo').value,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 it = 0; i < len ;it++)
{
steps+=route.Itinerary.Segments[it].Instruction+" -- (";
steps+=route.Itinerary.Segments[it].Distance+") ";
steps+=route.Itinerary.DistanceUnit+"\n";
}

routeinfo+="Steps:\n"+steps;

//document.getElementById('txtDirections').value = routeinfo;
alert(routeinfo);
}
</script>

</head>

<body>
<div id='myMap' style="position:relative; width:545px; height:400px;"></div>

<table style="vertical-align:top">
<tr style="vertical-align:top">
<td style="width:250px; vertical-align:top">
From &nbsp;&nbsp;
<input id="txtFrom" type="text" name="txtFrom" />
</td>

<td style="width:400px; vertical-align:text-top;">
To &nbsp;&nbsp;
<input id="txtTo" type="text" name="txtTo" />
<input id="location" type="button" value="Get Directions" name="directions" onclick="GetDirections();" />
</td>
</tr>
</table>

</body>

</html>





Re: issue with getroute() ie7

TheClansman

I tested this and it worked fine in IE7 and Firefox, although it did produce this bug:

"
route.Itinerary.Segments[it] has no properties
steps+=route.Itinerary.Segments[it].Instruction+" -- (";
"

My guess is that it has something to do with your for loop, if you notice you use a var called it, but then you have i<len. I am not sure where i comes from, but that is the reason I get an error and possibly the reason it will not work for you.







Re: issue with getroute() ie7

Bryan Higgins

I was able to duplicate your problem, and I see what the problem is now. You are creating a new map object with every routing request, which is not recommended. If you change your GetDirections function in the following way, the route request is processed correctly:

Code Block

var map = null;

function GetDirections()
{
if (map == null)
{
map = new VEMap('myMap');
map.LoadMap();
}
map.GetRoute(document.getElementById('txtFrom').value,document.getElementById('txtTo').value,null,null,onGotRoute);
}

It looks like there are also some issues with onGotRoute, that the other poster mentioned, but that does not relate to the original problem.

I hope this helps Smile






Re: issue with getroute() ie7

TheClansman

hmm, I never noticed that it was only happening on the second attempt. Was able to reproduce the error, the fix is to not load the map everytime you get directions. I took the top two lines of your GetDirections function and added them into a new function called GetMap, then added <body onload="GetMap();"> and it fixed it up.