目前我有一個這樣的代碼來在我的 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;
如果我使用我的網址,https://maps.google.com/maps?q=%s,%s那么它可以正常作業,但是當我使用我的網址時,https://maps.google.com/maps?q=%s,%s&output=embed它會提示錯誤“必須在 iframe 中使用 Google Maps Embed API”,如圖所示
有沒有辦法在我的 delphi 專案中使用 iframe?
uj5u.com熱心網友回復:
正如錯誤訊息所說,Google 的嵌入式地圖希望以 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;
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/389111.html
