Delphi XE6 calls Baidu map via JavaScript API

Source: Internet
Author: User

Reference yesterday's content, have a friend or ask how to call Baidu map, also, who let us all in the domestic, no way, you understand.

First go to apply for a key, and then look at the first example of Baidu JavaScript: http://developer.baidu.com/map/jsdemo.htm

The next step is to move the code in the example to Twebbrower.

Unit Unit3;

Interface

Uses
System.sysutils, System.types, System.uitypes, system.classes, System.variants,
FMX. Types, FMX. Controls, FMX. Forms, FMX. Graphics, FMX. Dialogs, FMX. WebBrowser,
Fmx.stdctrls;

Type
TFORM3 = Class (Tform)
Webbrowser1:twebbrowser;
Button1:tbutton;
Procedure Formcreate (Sender:tobject);
Procedure Button1Click (Sender:tobject);
Private
{Private declarations}
Public
{Public declarations}
End

Var
FORM3:TFORM3;

Const
S= ';//equal to the content of the Web page, I posted it, it was messy, had to explain here.
s1=

' var map = new Bmap.map ("Allmap"); '
+ ' var point = new Bmap.point (116.404, 39.915); '
+ ' Map.centerandzoom (point,15); '

+ ' map.enablescrollwheelzoom (); '
;//The JavaScript code to execute


Implementation

{$R *.FMX}

Procedure Tform3.button1click (Sender:tobject);
Begin
WebBrowser1. Evaluatejavascript (S1);//execute JavaScript code on the Web page.
End

Procedure Tform3.formcreate (Sender:tobject);
Begin
WebBrowser1. Loadfromstrings (S, ' http://api.map.baidu.com ');//Transfer into web page

End

End.

Note the issue:

1. Only Fmx.webbrowser supports Evaluatejavascript and Loadfromstring methods, and the Twebbrowser of VCL is not supported.

2.FMX. WebBrowser only supports Android IOS and does not support WIN32

3.LoadFromStrings when you call a Web page, you specify the second parameter, or the map is not displayed

Regret:

Feel the map display speed is not good, when you click on the button, will flash, to the performance of the FMX or the reason for this call method generated? It's not clear.

Finally, attach:

Postscript:

Baidu for the mobile phone to provide a dedicated JavaScript API, called fast xxx, I tried to call, not out of the map, do not know what the reason. It is estimated that this will improve the reaction speed.

Http://blog.sina.com.cn/s/blog_44fa172f0101ri82.html

Delphi XE6 calls Baidu map via JavaScript API

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.