[英]Using iframe for google maps embed api in multi device Delphi
Currently I have a code like this to display a google map with my current location in my TWebBrowser目前我有这样的代码来显示谷歌 map 和我在 TWebBrowser 中的当前位置
procedure TForm1.LocationSensor1LocationChanged(Sender: TObject; const
OldLocation, NewLocation: TLocationCoord2D);
begin
var URLString := Format('https://maps.google.com/maps?q=%s,%s&output=embed', [Format('%2.6f', [NewLocation.Latitude]), Format('%2.6f', [NewLocation.Longitude])]);
WebBrowser1.Navigate(URLString);
end;
If I use my URL as https://maps.google.com/maps?q=%s,%s
then it works properly but when I use my URL as https://maps.google.com/maps?q=%s,%s&output=embed
then it will prompt an error "The Google Maps Embed API must be used in an iframe" as shown in the picture If I use my URL as
https://maps.google.com/maps?q=%s,%s
then it works properly but when I use my URL as https://maps.google.com/maps?q=%s,%s&output=embed
然后会提示错误“The Google Maps Embed API must be used in an iframe”如图
Is there a way I could have an iframe in my delphi project?有没有办法在我的 delphi 项目中拥有 iframe ?
As the error message says, Google's embedded map wants to be hosted in an HTML <iframe>
.正如错误消息所述,Google 的嵌入式 map 希望托管在 HTML
<iframe>
中。 TWebBrowser
has a LoadFromStrings()
method that you can use for that purpose, eg: TWebBrowser
有一个可用于该目的的LoadFromStrings()
方法,例如:
procedure TForm1.LocationSensor1LocationChanged(Sender: TObject;
const OldLocation, NewLocation: TLocationCoord2D);
begin
var URL := Format('https://maps.google.com/maps?q=%2.6f,%2.6f&output=embed', [NewLocation.Latitude, NewLocation.Longitude]);
var HTML = Format('<iframe src="%s" width="%d" height="%d" style="border:0;" allowfullscreen="" loading="lazy"></iframe>', [URL, <DesiredWidth>, <DesiredHeight>]);
WebBrowser1.LoadFromStrings(HTML, URL);
end;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.