Earlier this week I was thinking, wouldn't it be cool if the MapQuest .NET API would allow me to program all my logic in C# (or VB.NET) and then instead of having it generate a bitmap, have it generate just the URL of a map? The URL can be used in web applications or I can embed the url in an image tag which I send as an email. A whole new world of possibilities opens up. Guess what? Generating an URL for a MapQuest map is part of the API today!

In a previous blog post I described how to use the Exec object to create a bitmap of a map:

sbyte[] imageBytes = Exec.GetMapImageDirect( session );
byte[] bytes = (byte[]) (Array) imageBytes;

MemoryStream stream = new MemoryStream( bytes );
Bitmap bitmap = new Bitmap( stream );

Using the same Exec object, just use the GetMapDirectURLEx method to build an URL to the same image.

string url = Exec.GetMapDirectURLEx( session, new MQClientInterface.DisplayState() );
Just assign the URL to an the ImageURL property of an ASP.NET Image control and the map will be displayed.
imgMap.ImageUrl = url;   // imgMap is an Image control

I ran my code on the development environment and as such I get back a reference to the MapQuest dev box:

http://map.dev.mapquest.com//mqserver.dll?e=0&GetMapDirect.1=Session:5,MapState:,,314159.265358,314159.265358,11.111111,8.333333,0,
CoverageStyle:2,,DTStyle:3072,0,2147483647,MQ09191,0,0,1,-1,,-1,-1,-1,-1,-1,-1,
DTStyle:3073,0,2147483647,MQ09192,0,0,1,-1,,-1,-1,-1,-1,-1,-1,
FeatureCollection:2,PointFeature:,3072,0,,,0,45.36333,-68.504058,32767,32767,
PointFeature:,3073,0,,,0,45.315357,-68.474258,32767,32767,
PrimitiveCollection:1,LinePrimitive.2:3617,RouteShape,1,255,65280,150,0,
LatLngCollection.1:7,45363330,-68504058,-6889,-3235,-7343,-9316,-6359,6417,-11261,9460,-14687,23003,-1434,3471,
PointCollection:0,BestFit.2:1.2,1,DTCollection.1:0,0,0,DisplayState.1:0,72,1,
Authentication.3:b70fHwouU7>yb446,73655,,
NET_5.3.0_RC1,2141274732,

As you can see my route from work to home is not very long :-)