I've just started programming in Delphi and I have a problem with Google Map Api. I want to have a form with google map and draw lines on it(coordinates from db). Unfortunately when I try to put a 'Polyline' on a map the error occurs an error.
Line: 0
Char: 0
Error: Script error
Code: 0
Url: https://maps.googleapis.com/maps-api-v3/api/js/29/14b/intl/pl_ALL/poly.js
Have no idea how to fix it.
FYI I'm using RAD Studio 10.2 and using TWebBrowser component.
My code:
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.