![](/img/trans.png)
[英]Google Maps API error: RefererNotAllowedMapError in android device
[英]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.