【发布时间】:2017-10-12 19:26:08
【问题描述】:
我刚开始在 Delphi 中编程,但我遇到了 Google Map Api 的问题。我想要一个带有谷歌地图的表格并在上面画线(来自数据库的坐标)。不幸的是,当我尝试在地图上放置“折线”时,错误会发生错误。
行:0
字符:0
错误:脚本错误
代码:0
网址:https://maps.googleapis.com/maps-api-v3/api/js/29/14b/intl/pl_ALL/poly.js
不知道如何解决。
仅供参考,我正在使用 RAD Studio 10.2 并使用 TWebBrowser 组件。
我的代码:
unit Unit2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.OleCtrls, SHDocVw, MSHTML ;
type
TForm2 = class(TForm)
WebBrowser1: TWebBrowser;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
Doc: Variant;
HTMLWindow2: IHTMLWindow2;
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
var
HTMLStr: AnsiString =
'<!DOCTYPE html>' +
'<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">' +
' <head>' +
' <meta http-equiv="X-UA-Compatible" content="IE=edge" /> ' +
' <style>' +
' #map {' +
' height: 400px;' +
' width: 100%;' +
' }' +
' </style>' +
' </head>' +
' <body>' +
' <h3>My Google Maps Demo</h3>' +
' <div id="map"></div>' +
' <script src="https://maps.googleapis.com/maps/api/js?v=3&key=***&callback=initMap"></script>'+
' <script>'+
' function initMap() {' +
' var map = new google.maps.Map(document.getElementById("map"), {' +
' zoom: 3,' +
' center: {lat: 0, lng: -180},' +
' mapTypeId: "terrain"' +
' });' +
' var flightPlanCoordinates = [' +
' {lat: 37.772, lng: -122.214},' +
' {lat: 21.291, lng: -157.821},' +
' {lat: -18.142, lng: 178.431},' +
' {lat: -27.467, lng: 153.027}' +
' ];' +
' var flightPath = new google.maps.Polyline({' +
' path: flightPlanCoordinates,' +
' geodesic: true,' +
' strokeColor: "#FF0000",' +
' strokeOpacity: 1.0,' +
' strokeWeight: 2' +
' });' +
' flightPath.setMap(map);' +
' }' +
' </script>' +
' </body>' +
'</html>';
procedure TForm2.FormCreate(Sender: TObject);
begin
if NOT Assigned(WebBrowser1.Document) then
WebBrowser1.Navigate('about:blank');
Doc := WebBrowser1.Document;
Doc.Clear;
Doc.Write(HTMLStr);
Doc.Close;
HTMLWindow2 := (WebBrowser1.Document as IHTMLDocument2).parentWindow;
end;
end.
【问题讨论】:
-
如果不发布不起作用的代码的完整示例,您不可能在这里得到答案。以下是有关如何在 Delphi 应用程序中使用 Google 地图的一些示例的答案:stackoverflow.com/questions/10843029/google-maps-non-web-access 我回应了建议使用包装器的答案之一。我个人使用商业 TMS WebGMaps 包装器。
-
你在使用 GmLib 吗?
-
@MarkElder 很抱歉没有提供代码示例。现在已经完成了。
-
@JohnEasley 不,我没有使用 Gmlib,但我会看看这个库。
标签: delphi google-maps-api-3 twebbrowser