Einzelnen Beitrag anzeigen

Klaus01

Registriert seit: 30. Nov 2005
Ort: München
5.771 Beiträge
 
Delphi 10.4 Sydney
 
#6

AW: Openstreetmaps und Indy

  Alt 5. Mär 2024, 11:11
..oder so:

Delphi-Quellcode:
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;
Grüße
Klaus
Klaus

Geändert von Klaus01 ( 5. Mär 2024 um 11:14 Uhr)
  Mit Zitat antworten Zitat