You contacted me, I will come back to it on this thread :). I would advice against using the HTML snippet for interaction with the Google Maps API. If you want something like this the best idea would be to use a widget which already handles a lot of the heavy lifting like async loading the Google Maps API and drawing manager which you need.
Use my Google Maps Polygon widget and configure it to draw polylines. You can use the demo project for it. Draw a polyline with two points and finish the polyline. The widget will retrieve both sets of coordinates: ((x1,y1),(x2,y2)) and put it in a coordinatesString attribute. You can use that value to do further calculations