<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<html xmlns="
http://www.w3.org/1999/xhtml" >
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Map</title>
<script type="text/javascript" src="
http://dev.virtualearth.net/mapcontrol/v3/mapcontrol.js"></script>
<script type="text/javascript" language="javascript">
var map = null;
var XMLHttp = null;
var BuildingCoords = null;
function GetMap()
{
map = new VEMap('map');
map.LoadMap(new VELatLong(33.504114945297374, -86.79941654205322), 17 ,'h' , false);
}
function GetCoords()
{
var coords = document.getElementById("Buildng1");
coords.value = map.GetCenter();
}
function GetDirs()
{
var build1 = document.getElementById("txtFrom");
var build2 = document.getElementById("txtTo");
var url = "GetCoords.aspx?Building1=" + build1.value + "&Building2=" + build2.value;
getXMLHttp();
if(XMLHttp != null)
{
XMLHttp.open("GET", url);
XMLHttp.onreadystatechange = stateChanged;
XMLHttp.send(null);
}
}
function stateChanged()
{
if(XMLHttp.readyState == 4 && XMLHttp.status == 200)
{
BuildingCoords = XMLHttp.responseText;
var brk = BuildingCoords.indexOf("|");
var Building1 = BuildingCoords.substr(0, brk);
var Building2 = BuildingCoords.substr(brk + 1);
/* var bld1 = document.getElementById("Buildng1");
bld1.value = Building1;
var bld2 = document.getElementById("Buildng2");
bld2.value = Building2; */
var bld1brk = Building1.indexOf(", ");
var bld1lat = Building1.substr(0, bld1brk);
var bld1lon = Building1.substr(bld1brk + 2);
var bld2brk = Building2.indexOf(", ");
var bld2lat = Building2.substr(0, bld2brk);
var bld2lon = Building2.substr(bld2brk + 2);
var point1 = new VELatLong(bld1lat, bld1lon);
var point2 = new VELatLong(bld2lat, bld2lon);
map.GetRoute(point1, point2);
}
}
function getXMLHttp()
{
if(window.ActiveXObject)
{
try
{
XMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
XMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
}
}
}
else if(window.XMLHttpRequest)
{
try
{
XMLHttp = new XMLHttpRequest();
}
catch(e)
{
}
}
}
</script>
<style type="text/css">
.map {
position: absolute;
top: 20;
left: 10;
width: 400px;
height: 400px;
border:#555555 2px solid;
}
The commented out sections were simply used to get the latitude and longitude co-ordinates of the various places to store in the database alongside the local name.
And here is the web page that the XMLHttp request calls to return the co-ordinates of the places.
The first page (default.aspx - the one that actually displays the map) has no code behind.
The second page (GetCoords.aspx) really only has code behind. I didn't touch the .aspx page itself.