Google map uses Google. Maps. polyline to draw multiple line segments.
JavascriptCode:
VaR polyline;
// Draw a polygon Google. Maps. polyline Function Drawpolyline (latlngarray ){ VaR Path = New Array (); VaR Latlngs = latlngarray. tostring (). Split (";" ); For (IndexIn Latlngs ){ VaR Latlng = latlngs [Index]. Split ("," ); If (Latlng. Length = 2 ) {Path. Push (( New Google. Maps. latlng (latlng [0], latlng [1 ]);} Polyline = New Google. Maps. polyline ({map: map, path: path, geodesic: True , Strokecolor: "# Ff0000" , Strokeopacity: 0.6 , Strokeweight: 2 });} Function Clearpolyline (){ If (Polyline! = Null ) {Polyline. setmap ( Null );}}
C # Call code:
Public static string drawpolyline (webbrowser WB, list <pointf> ptlist)
{
Stringbuilder sb = new stringbuilder ();
Foreach (VAR item in ptlist)
{
SB. appendformat ("{0}, {1};", item. Y, item. X );
}
Object [] objarray = new object [1] {sb. tostring (). trimend (';')};
String optname = "drawpolyline ";
Return donegooglemapop (WB, optname, objarray );
}
// Execute script commands Private Static String Donegooglemapop (webbrowser WB, String Optname, object [] objarray ){ String Retstr = "" ; Try {Object objret = WB. Document. invokescript (optname, objarray ); If (Objret! = Null ) Retstr = Objret. tostring ();} Catch {} Return Retstr ;} // Draw trajectory data Public Static String Drawpolyline (webbrowser WB, list <latlng> Tracklist) {list <Pointf> ptlist = New List <pointf> (); Tracklist. foreach (item => Ptlist. Add ( New Pointf (( Float ) Item. lng ,( Float ) Item. LAT ))); Return Drawpolyline (WB, ptlist );} // Clearpolyline Public Static String Clearpolyline (webbrowser WB ){ Return Donegooglemapop (WB, " Clearpolyline " , Null );}
Call with actual parameters:
Drawpolyline (wbgooglemap, tracklist );