windows_mss


When I Select Source & Destination Dynamically, Path Getting Scatter Across The Map

hi,

i can able to get the Correct Route and Path for the corresponding Source

and destination, like this,

map.GetRoute('Redmond, Washington, United States','seattle, Washington, United States',VEDistanceUnit.KiloMeter,VERouteType.Shortest);

when i try to do the same dynamically, i fails there,

<html>
<head>
<title>Driving Directions in Virtual Earth</title>
<style type="text/css" media="screen"> ul, li {margin:0;padding:0;}
ul.popMenu { position:absolute; margin: 0; padding: 0px; list-style: none; font-family: arial; font-size:10px; text-align: center; width: 100px; /* Width of Menu Items */ border: 1px solid #ccc; background:white; display:none; }
ul.popMenu li { position: relative; }
/* Styles for Menu Items */ ul.popMenu li a { display: block; text-decoration: none; color: black; padding: 1px 1px 0px 1px; }
ul.popMenu li a:hover { background:#335EA8; color:white; }
.msg {filter: alpha(opacity=80);opacity: .8;z-index: 3;width: 15em;height: 15em;border: solid 1px black;background: white; visibility: hidden;overflow: auto;font-family: Verdana;font-size: 75%;position: absolute;}
.cont { z-index: 3;width: 15em; height: 5em;border: solid 1px black; background: white; position: absolute;}
</style>
<script src="http://dev.virtualearth.net/mapcontrol/v4/mapcontrol.js"></script>
<script>
var map = null;
var pLat;
var pLon;
var stPoint = null;
var ePoint = null;

//function OnPageLoad()
//{
// map = new VEMap('myMap');
// map.LoadMap(new VELatLong( 19.06,81.65), 4, 'r', false);
// map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
// map.AttachEvent("oncontextmenu", SPopupMenu);
//}

//1.3.1115150037.31";
//var map = null;
var le = 0;
function OnPageLoad()
{
var head = document.getElementsByTagName("head")[0];
var s = document.createElement('script');
s.id = 'VEScript';
s.type = 'text/javascript';
s.src = "http://maps.live.com/veapi.ashx v=1.3.1204222815.33";
head.appendChild(s);
DelayGetMap();
}
function DelayGetMap()
{
try {
map = new VEMap('myMap');
//document.getElementById("myLoading").style.display = "none";
document.getElementById("myMap").style.display = "block";
//map.LoadMap(new VELatLong(21.6, 85.33), 10 ,'h' ,false);
map.LoadMap(new VELatLong( 19.06,81.65), 4, 'r', false);
map.SetScaleBarDistanceUnit(VEDistanceUnit.Kilometers);
map.AttachEvent("oncontextmenu", SPopupMenu);
}catch(err)
{
if (le < 30)
{
le++;
setTimeout("DelayGetMap()",51);
alert("Site is busy.");
GetMap();
}
}
}

function SPopupMenu(e)
{
pLat = e.view.LatLong.Latitude;
pLon = e.view.LatLong.Longitude;
var latlong = map.LatLongToPixel(new VELatLong(pLat,pLon));

var x = map.GetLeft();
var y = map.GetTop();

var menu = document.getElementById('popupmenu');
menu.style.display='block'; //Showing the menu
menu.style.left = latlong.x + x; //Positioning the menu
menu.style.top = latlong.y + y;
}

function rmPopupMenu()
{
var menu = document.getElementById('popupmenu').style.display='none';
}

function SetStart()
{
try
{
map.DeletePushpin('start');
} catch(err) {}

stPoint = new VELatLong(pLat, pLon);
var pin = new VEPushpin('start', stPoint, null, 'Start Here', 'Starting point');
map.AddPushpin(pin);

rmPopupMenu();
}

function SetEnd()
{
try
{
map.DeletePushpin('end');
} catch(err){}

ePoint = new VELatLong(pLat, pLon);
var pin = new VEPushpin('end', ePoint, null, 'pin', 'end');
map.AddPushpin(pin);

rmPopupMenu();
}

function gDir()
{
map.GetRoute(stPoint, ePoint, VEDistanceUnit.Kilometers, null, GRoute);
rmPopupMenu();
}

function GRoute(route)
{
var rtInfo ="Total distance:"+route.Itinerary.Distance+route.Itinerary.DistanceUnit;
document.getElementById("info").innerHTML = rtInfo;

}
</script>
</head>
<body onload="OnPageLoad();" style="OVERFLOW:hidden">
<div id="info" style="Width:100px;Height:15px;Font-family:Arial;Font-size:12px;display:block;"></div>
<div id="myMap" style="WIDTH:800px;POSITION:relative;HEIGHT:650px">
</div>
<DIV>
<ul id="popupmenu" class="popMenu">
<li>
<a href="#" onclick='SetStart()'>Start</a>
<a href="#" onclick='SetEnd()'>End</a>
<a href="#" onclick='gDir()'>ShowRoute</a></li>
</ul>
</DIV>
<!-- <DIV id="Dt" style="WIDTH: 100px; HEIGHT: 10px"></DIV> -->
</body>
</html>

Please Guide Me,

Thanks In Advance





Re: When I Select Source & Destination Dynamically, Path Getting Scatter Across The Map

Mo Majad


Hi, Your code works for me [if my understanding of what it is doing is correct]

Basically I can right click choose start and end points and then plot route, the only problem is the blue line is not where it should be. and subsequent polloting of routes doesnt work that well

regards, Mo






Re: When I Select Source & Destination Dynamically, Path Getting Scatter Across The Map

windows_mss

hi,

i too needed that Blue line is to lies over the route.

then how to find the location name for the Starting and ending point







Re: When I Select Source & Destination Dynamically, Path Getting Scatter Across The Map

SoulSolutions

So the answer is that this line was missing from the <head>:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

John.