kovacszozo


Dear all !
I'll write a html code like this: in html have two textbox and one button. I write two cityes in the textboxes and when I press the button this will call a JavaScript function and this will write the distance between the two cityes. And the program should not draw any map like in the microsoft earth! Please Help!
Sorry my is english wrong!



Re: Simple Program -Help

wjcyg


It's not quite THAT simple. First, are you looking for the straight line distance or a driving distance If you want straight line distance, it is simply an exercise in geometry. Do a Google search on "distance between cities latitude longitude" and you'll find sites like: http://www.4guysfromrolla.com/webtech/010500-1.shtml that include algorithms for doing the calculation.

If you want the driving distance created from a route in VE, then you've got additional issues. You have to create a map in code even if you don't display the div you put it in. Then you have to do finds on each city (http://msdn2.microsoft.com/en-us/library/bb429645.aspx) and then build a route (http://msdn2.microsoft.com/en-us/library/bb429548.aspx) and then get the itinerary (http://msdn2.microsoft.com/en-us/library/bb412480.aspx) and interogate its distance property (http://msdn2.microsoft.com/en-us/library/bb429557.aspx).

Did I miss anything

Walt






Re: Simple Program -Help

kovacszozo

Here is my code is good write a distance between Budapest and Amsterdam and drawing, but I do not want to draw only write a distance.How is needed to modify this code
<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();
var s="Budapest,hungary";
var e="Amsterdam,Netherlands";
map.GetRoute(s,
e,
null,
null,
onGotRoute);
}
function onGotRoute(route)
{
var routeinfo="Route info:\n\n";
routeinfo+="Total distance: ";
routeinfo+= route.Itinerary.Distance*1.60+" "+"km";
alert(routeinfo);
}
</script>
</head>
<body onLoad="GetMap()" >
<div id='myMap' style="position:relative; width:400px; height:400px;"></div>
</body>
</html>>






Re: Simple Program -Help

Derek Chan

Hi,

I don't believe there is anyway to disable the autozoom and center on successful GetRoute calls (ever since V3). You could re-position the map to the original location in your callback function, but the map would still flash around. If you absolutely need this functionality I would recommend leveraging the Mappoint Web Service to get your route distances and directions (http://msdn2.microsoft.com/en-us/library/aa502074.aspx)


Hope that helps,






Re: Simple Program -Help

wjcyg

In your style sheet, you can set the div's properties to "visibility:hidden; display: none;". The div is still there, just not displayed. I think that would work.

Walt





Re: Simple Program -Help

kovacszozo

Thank you very much!