As an algorithm, please try this. Now, I am assuming that you are using Google-map as you indicated.
1) Read the map as an image (metafile).
2) In Google map roads should have a specific value (or values in a narrow dynamic range). For example, larger roads in yellow and smaller roads in white colors.
3) First, do a thinning-processing (a morphological image processing). Thus, objects on the map become single pixel (s) or connection of the single pixels (roads). Also, see skelotonization of an image.
4) Then, define the departure point A and terminal point B. Save these coordinates in some variables. At the same time, define the pixel value for the road you are going to track (for example, a pixel value corresponding to a yellow pixel). Actually, this is a labeling issue in image processing. Sometimes it is called connectivity labeling. The main idea is extracting same object(s) or similar areas from an image.
5) Now, it’s time to start labeling (namely, compare the current pixel with its surrounding eight pixels- candidate pixels), if their values is a match count it as "1", and save it some place (as Matched Pixels). In general, among the eight pixels, only one pixel should be matched to the Current pixel (We did thinning-processing).
Now, the candidate pixel, which was matched, becomes the "Current Pixel”. This is an iteration process, repeat this. At the end, if everything is OK, you will reach the Terminal Point B. When, you got in the terminal point, stop the iteration and count all Matched Pixels, so that you can get distance (because you know the pixel’s size. Namely, in maps or satellite images, each pixel is corresponding to some area, e. g., XX- square meters. We call this spatial resolution). Now, you got a path and distance between A and B, [distance-1:D1].
6) Flip the image in X-direction, then rotate it 180-degrees. Now, the previous terminal point B becomes the new Departure point A. Repeat the steps of 4) and 5) again. Now, you got a path between the new A and B. If there are more than one road between A and B, you got two paths-the second distancel [distance-2: D2]. If there is only one road, you got almost the same distance with D1.
7) Then, C#, System.Math.Min(D1,D2). You got the answer.
Updated 8-Jun-12 17:03pm
v4