[C # winfrom using Google map] draw trajectory lines on a map

Source: Internet
Author: User
Tags polyline

 

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 );

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.