繁体   English   中英

使用 iframe 谷歌地图在多设备 Delphi 中嵌入 api

[英]Using iframe for google maps embed api in multi device Delphi

目前我有这样的代码来显示谷歌 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然后会提示错误“The Google Maps Embed API must be used in an iframe”如图在此处输入图像描述

有没有办法在我的 delphi 项目中拥有 iframe ?

正如错误消息所述,Google 的嵌入式 map 希望托管在 HTML <iframe>中。 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM