C#winform and Baidu API Interactive-----Read the parameters of JS

Source: Internet
Author: User
Tags polyline

On Baidu's API

<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<meta name= "viewport" content= "initial-scale=1.0, User-scalable=no"/>
<style type= "Text/css" >
Body, HTML, #allmap {width:100%;height:100%;overflow:hidden;margin:0;font-family: "Microsoft Jas Black";}
</style>
<script type= "Text/javascript" src= "http://api.map.baidu.com/api?v=2.0&ak= Your Keys" ></script>
<title> ranging </title>
<body>
<div id= "Allmap" ></div>
</body>
<script type= "Text/javascript" >
Baidu Map API Features
var map = new Bmap.map ("Allmap");
Map.centerandzoom ("Chongqing", 12); Initialize the map to set the city and map levels.
var pointa = new Bmap.point (106.486654,29.490295); Create point coordinates a--Dadukou District
var pointb = new Bmap.point (106.581515,29.615467); Create point coordinates b--Jiangbei District
Alert (' Distance from Dadukou District to Jiangbei District: ' + (map.getdistance (POINTA,POINTB) '). ToFixed (2) + ' M.  ‘); Get two point distance, keep two decimal places
var polyline = new Bmap.polyline ([Pointa,pointb], {strokecolor: "Blue", Strokeweight:6, strokeopacity:0.5}); Defining polylines
Map.addoverlay (polyline); Add a polyline to the map
function getdistance ()//This is self-added, define a method and then let WinForm call, (of course, can also be reversed, WinForm define a method, JS in the re-call)
{return map.getdistance (POINTA,POINTB). toFixed (2);}
</script>

——————————————————————————————————————————————————————————————————————————————————————

Add Control Webbrower

Adding code to form load

String str_url = Application.startuppath + "\\HTM name. htm";              HTM to be placed in the debug directory, if you do not have to start the directory to put any directory string str_url= ""; do it yourself. Uri url = new Uri (Str_url);            Webbrogis.url = URL; Webbrogis.objectforscripting = this;

On WinForm Code

var s = webBrowser1.Document.InvokeScript ("getdistance");//quotation marks are function names, note that variables should be var type

Txtbox.text=s.tostring ();

-----------------------------------------------------------

Several questions 1 garbled to change the charset to gb2312,2 secret key to search online

C#winform and Baidu API Interactive-----Read the parameters of JS

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.