Delphi Call Baidu Map API

Source: Internet
Author: User

First, the method of invoking JavaScript

Two kinds:

The first type: The method of using the self-coding function

function Executejavascript (webbrowser:twebbrowser; code:string): Variant;
var//Send Script
Document:ihtmldocument2;
Window:ihtmlwindow2;
Begin
Execute JavaScript in WebBrowser
Document:=webbrowser.document as IHTMLDocument2;
If not Assigned (Document) then Exit;
Window:=document.parentwindow;
If not Assigned (Window) then Exit;
Try
Result:=window.execscript (Code, ' JavaScript ');
Except
On e:exception does raise Exception.create (' Javascript error ' +e.message+ ' in: ' #13 #10+code);
End
End

The second type: Call WebBrowser built-in methods directly:

WebBrowser1.OleObject.document.parentWindow. Method name ();

Second, the Call of Baidu API

Make an HTML file

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<meta name= "viewport" content= "initial-scale=1.0, User-scalable=no"/>
<script type= "Text/javascript" src= "http://api.map.baidu.com/api?v=2.0&ak= your secret key" ></script>
<title> Baidu Map Test </title>
<style type= "Text/css" >
Body, HTML, #allmap {width:100%;height:100%;overflow:hidden;margin:0;}
</style>
<body>
<div id= "Allmap" > </div>

</body>


<script type= "Text/javascript" >

function SetCenter (areaname) {//Set new map Center

Map.centerandzoom (areaname,10);
}

var map = new Bmap.map ("Allmap"); JS Main program, Tune up Baidu map
var point = new Bmap.point (116.404, 39.915);
Map.centerandzoom (point,5);
Map.enablescrollwheelzoom ();

</script>

Third, the implementation of DELPHI method:

WebBrowser1.Navigate (Extractfilepath (application.exename) + ' bmap.html ');

Try
Executejavascript (WebBrowser1, ' SetCenter ("' +centercityname+ '");
Except
On E:exception do ShowMessage (e.message);
End

{

Or:

WebBrowser1.OleObject.document.parentWindow.setcenter (Centercityname);

}

Delphi Call Baidu Map API

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.