Discussion:
[Lazarus] Google geocoding API help
DougC via Lazarus
2018-06-05 14:15:53 UTC
Permalink
I'm working through how to obtain LAT/LONG for street addresses in the USA and just found GMLib at http://www.cadetill.com/gmlib/ This library is more than I need but I'm working my way through the source to find what I need.

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. No mapping involved - I'll do that later.

Doug C.
leledumbo via Lazarus
2018-06-08 01:11:25 UTC
Permalink
Post by DougC via Lazarus
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/
--

Loading...