Route Geometry Exposed

This week at the Location Intelligence Conference, I announced that route geometry is now exposed in Virtual Earth. The SDK is now updated to reflect how you can get route geometry out of Virtual Earth. The catch is you have to use the tokening system by Implementing Customer Identification. Once you've authenticated, you will have access to the VERoute.ShapePoints Property. The way it works is that once you've calculated a route, you can use a callback to get the route geometry from the route.

Here's a snippet of code I stole from an application that Johannes Kebeck wrote which combines SQL Server 2008 Spatial and Virtual Earth. In fact, Johannes has posted an entry about "FindNearRoute with Virtual Earth 6.1 and SQL Server 2008" on his blog.

function GetRoute()

{

var options = new VERouteOptions;

options.RouteCallback = RouteCallback;

var locations = new Array(document.getElementById('txtStart').value, document.getElementById('txtEnd').value);

map.GetDirections(locations, options);

}

function RouteCallback(route)

{

myRouteGeom = route.ShapePoints;

}

The first function (GetRoute()) is a custom JavaScript function which takes input from the user via a web form, creates an array for the origin (txtStart) and destination (txtEnd) then passes the array into the GetDirections() method for route calculation. Then we use the optional callback function in VERouteOptions.RouteCallback and set it to our second custom JavaScript function (RouteCallback()). Once the route calculation is complete, the callback will fire and we'll get the route geometry out of the route, stick it in the variable "myRouteGeom" and do whatever it is we'd like with it.

For this scenario I discussed at Location Intelligence, you would send the route geometry to SQL Server 2008 Spatial, set a buffer around the route geometry and search against a database of points of interest to find which points of interest are along the route. This would replace the need to use MapPoint Web Service's FindServiceSoap.FindNearRoute() method.

Exposing this method has a lot of implications in terms of bringing Virtual Earth closer together with Microsoft SQL Server 2008. Ed Katibah (Spatial Program Manager for SQL Server) demonstrated some functionality for setting a buffer, clipping the route based on it staying within a boundary and querying against a point set. So, let's say you're driving from San Diego to Seattle (sort of how I migrated to the PacNW) and you want to find all of the Starbucks along the way, but you only care about those in Oregon (because that's where the clouds really kick in and it's just plain tiring!). We'll, you can get the route geometry out of Virtual Earth, send it to SQL Server 2008, clip it based on the polygonal shape of the state of Oregon, and then query against a local copy of Starbucks locations. Optionally, you can pass the clipped route and points down to Virtual Earth for visualization. There are tons of scenarios this opens the doors for, so send me some of your cool demos and maybe your site will be the next one I show on stage.

CP