[Lazarus] Google geocoding API help

leledumbo leledumbo_cool at yahoo.co.id
Fri Jun 8 03:11:25 CEST 2018


> In the meantime I'm asking if anyone knows of a simple how-to or demo or
example of just sending a street address through the Goggle API
and just getting back LAT and LONG values

{$H+}

uses
  fphttpclient, fpjson, jsonparser;

var
  Address: String;
  AddressData,LocationData: TJSONObject;
begin
  Write('Enter an address: '); ReadLn(Address);
  AddressData :=
TJSONObject(GetJSON(TFPHTTPClient.SimpleGet('https://maps.googleapis.com/maps/api/geocode/json?address='
+ Address + '&key=well, you have to use your own key, it is not free
unfortunately')));
  LocationData :=
TJSONObject(AddressData.FindPath('results[0].geometry.location'));
  WriteLn('Latitude : ',LocationData.Floats['lat']:1:16);
  WriteLn('Longitude: ',LocationData.Floats['lng']:1:16);
end.

No error checking is intended, I'll leave that up to you.
Get your API key here:
https://developers.google.com/maps/documentation/geocoding/get-api-key



--
Sent from: http://free-pascal-lazarus.989080.n3.nabble.com/


More information about the Lazarus mailing list