delphi 怎么调用百度地图API,如下

2025-05-14 05:55:33
推荐回答(1个)
回答1:

一、调用javascript的方法
两种:
第一种:采用自编函数的方法
function ExecuteJavaScript(WebBrowser:TWebBrowser; Code: string):Variant;var //发送脚本Document:IHTMLDocument2;Window:IHTMLWindow2;begin// execute javascript in webbrowserDocument:=WebBrowser.Document as IHTMLDocument2;if not Assigned(Document) then Exit;Window:=Document.parentWindow;if not Assigned(Window) then Exit;tryResult:=Window.execScript(Code,'JavaScript');excepton E:Exception do raise Exception.Create('Javascript error '+E.Message+' in: '#13#10+Code);end;end
第二种:直接调用WebBrowser内置方法:
WebBrowser1.OleObject.document.parentWindow.方法名();
二、百度API的调用
制作一个HTML文件
百度地图测试




三、DELPHI 中的实现方法:
WebBrowser1.Navigate(ExtractFilePath(Application.ExeName)+'bmap.html')
tryExecuteJavaScript(WebBrowser1,'setcenter("'+CenterCityname+'");');excepton E:Exception do showmessage(E.Message);end
或者:
WebBrowser1.OleObject.document.parentWindow.setcenter(CenterCityname)