Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2018-06

Google geocoding API help

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

DougC

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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20180605/c39459e7/attachment.html>

Reply by email

leledumbo
to DougC
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

Reply by email