Achieving Avoid Highways (Motorways) with Microsoft's Virtual Earth

A common problem that many developers face when using the Microsoft Virtual Earth SDK is that out of the box, you cannot generate routes which avoid highways/motorways. This functionality is available on Google Maps but not via the Google Maps API. It is therefore necessary to look elsewhere for the functionality.

Fortunately, Microsoft's MapPoint Web Service does allow the option of using or avoiding highways on routes. Using XML and SOAP to receive the route now avoiding highways from the Web Service, we can take these routes and plot them within Virtual Earth. The main Web Service can be implemented using the the default Map Point web service found here: http://www.microsoft.com/mappoint/products/webservice/default.mspx. If you're using PHP then you can consume this service with NuSoap and PHP. Microsoft have provided a useful document on how to do this here: http://msdn.microsoft.com/en-us/library/ms980207.aspx.

Once you have received the full route from the Map Point Web Service, the next task is then to plot this on your Virtual Earth map. Using the VEMap.GetDirections method allows you to pass in a number of locations/waypoints for your route. For journeys greater than 25 waypoints (chances are it will be if you're avoiding highways) you can only select 25 different waypoints on your route using this method. To implement this you'll need to call the VEMap.GetDirections every 25 waypoints along your journey until you reach the end of the route and then plot this onto the map as a custom shape.

Motorways Avoid Motorways

Apologies for the badly cropped images. If you would like to know a bit more about this solution then just let me know.

To see a live example then head on to the Mr and Mrs Smith Route Planner: http://www.mrandmrssmith.com/routeplanner and to read about other features of the Route Planner, head over to the Lightmaker Blog.

No Comments