uses
System.SysUtils, system.IOUtils, REST.Client, rest.types;
function load_OSM_ToFile(
CONST FileName:
STRING;
CONST Angle_Left, Angle_Bottom, Angle_Right, Angle_Top: Extended): Boolean;
var
restClient: TRestClient;
restRequest: TRestRequest;
restResponse: TRestResponse;
formatSet: TFormatSettings;
begin
restClient := TRestClient.Create('
https://api.openstreetmap.org/api/0.6/map');
try
restCLient.Accept := '
application/json';
restClient.AcceptCharset := '
utf-8';
restRequest := TRestRequest.Create(
nil);
try
restRequest.Client := restClient;
restRequest.Accept := '
application/json';
restRequest.AcceptCharset := '
utf-8';
restRequest.Method := rmGet;
restRequest.AssignedValues := [TRESTRequest.TAssignedValue.rvAccept,
TRESTRequest.TAssignedValue.rvConnectTimeout,
TRESTRequest.TAssignedValue.rvReadTimeout];
formatSet := TFormatSettings.Create;
formatSet.DecimalSeparator := '
.';
restRequest.AddParameter('
bbox',format('
%s,%s,%s,%s',[floatToStr(Angle_Left, formatSet),
floatToStr(Angle_Bottom, formatSet),
floatToStr(Angle_Right, formatSet),
floatToStr(Angle_Top, formatSet)]));
var param := restRequest.params.AddHeader('
Accept', '
application/json');
param.Options := param.Options + [poDoNotEncode];
restResponse := TRestResponse.Create(
nil);
try
restRequest.Response := restResponse;
restRequest.Execute;
result := restRequest.Response.StatusCode = 200;
if result
then
TFile.WriteAllText(fileName, restResponse.Content);
finally
restResponse.Free;
end;
finally
restRequest.Free;
end;
finally
restClient.Free;
end;
end;