Geocoding

Exception: TJSONObject["status--\u0020You\u0020must\u0020enable\u0020Billing\u0020on\u0020the\u0020Google\u0020Cloud\u0020Project\u0020at\u0020https\u003A//console.cloud.google.com/project/_/billing/enable\u0020Learn\u0020more\u0020at\u0020https\u003A//developers.google.com/maps/gmp-get-started"] not found.
function TAddressGeoCoding4(faddr, fcountry: string): String; var Url,API_KEY, source: string; jo, locate: TJSONObject; urlid: TIdURI; fLat,fLong: double; begin urlid:= TIdURI.create(''); API_KEY:='785b4141b...................'; //get your own one please if fcountry <> '' then Url:= urlid.URLEncode('https://api.geocod.io/v1.7/geocode?q='+ fAddr+'&country='+fcountry+'&api_key='+API_KEY) else Url:= urlid.URLEncode('https://api.geocod.io/v1.7/geocode?q='+ fAddr+'&api_key='+API_KEY); jo:= TJSONObject.Create4(wdc_WinInet_HttpGet2(Url,Nil)); try jo.getString('input') locate:= jo.getJSONArray('results').getJSONObject(0).getJSONObject('location'); source:= jo.getJSONArray('results').getJSONObject(0).getString('source'); //geometry.getJSONObject('coordinates'); fLat:= locate.getDouble('lat') fLong:= locate.getDouble('lng'); result:=Format('Coordinates: lat %2.3f lng %2.3f :%s',[flat,flong,source]); except Xraise(Exception.Create(jo.getString('error'))); finally jo.Free; urlid.free; end; end;
writeln(TAddressGeoCoding4('Ontario','Canada'));>>> Coordinates: lat 50.445 lng -86.047 :CanVec+ by Natural Resources Canada
try jo.getString('input') locate:= jo.getJSONArray('results').getJSONObject(0).getJSONObject('location'); source:= jo.getJSONArray('results').getJSONObject(0).getString('source'); fLat:= locate.getDouble('lat') fLong:= locate.getDouble('lng'); result:=Format('Coordinates: lat %2.3f lng %2.3f :%s',[flat,flong,source]); except Xraise(Exception.Create(jo.getString('error'))); finally

OpenStreetMap

[{"place_id":282193469,"licence":"Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright","osm_type":"relation","osm_id":62578,"boundingbox":["50.8304399","51.0849743","6.7725303","7.162028"],"lat":"50.938361","lon":"6.959974","display_name":"Cologne, North Rhine-Westphalia, Germany","class":"boundary","type":"administrative","importance":0.9006323589104861,"icon":"https://nominatim.openstreetmap.org/ui/mapicons//poi_boundary_administrative.p.20.png"}]

--

--

Max Kleiner's professional environment is in the areas of OOP, UML and coding - among other things as a trainer, developer and consultant.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Max Kleiner

Max Kleiner

Max Kleiner's professional environment is in the areas of OOP, UML and coding - among other things as a trainer, developer and consultant.