Geocoding II

Geocoding is the processing of single addresses into geographic coordinates and can be performed by a number of free online web sites. Many of these same sites can also perform reverse geocoding, or the use of geographic coordinates to determine addresses or place names. The web site links below provide access to free single address or place name geocoding services. I want to show 2 of them, a commercial and a free one.
  • Geographic coordinates of Delphi, Greece
  • Latitude: 38°28'45" N Longitude: 22°29'36" E
  • Elevation above sea level: 560 m = 1837 ft


function TAddressGeoCodeOSM(faddress: string): string; var url, res, display: string; jo, location: TJSONObject; urlid: TIduri; windown: TWinApiDownload; begin urlid:= TIdURI.create(''); url:= urlid.URLEncode(' format=json&q='+fAddress); windown:= TWinApiDownload.create; windown.useragent:= 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1'; windown.url:= url; windown.download1(res); //windown.OnWorkStart StrReplace(res, '[{', '{'); jo:= TJSONObject.create4(res); try if jo.getString('place_id') <> ' ' then display:= jo.getstring('display_name'); result:= Format('Coords: lat %2.3f lng %2.3f :%s importance: %2.4f', [jo.getdouble('lat'),jo.getdouble('lon'),display, jo.getdouble('importance')]); except writeln('E: '+ExceptiontoString(exceptiontype, exceptionparam)); finally jo.Free;;; end; end;
constructor TWinApiDownload.Create; begin inherited; fUserAgent:= 'Mozilla/5.001(windows; U; NT4.0; en-US;) Gecko/25250101'; fProgressUpdateInterval:= 100; fCachingEnabled:= True; fStop:= False; fActive:= False; end;
with TWinApiDownload.create do begin Useragent:= 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1'; Url:= '' +flots(flat)+'&lon='+flots(flong)+'&zoom=10&format=json'; Download1(rest); //writeln(rest) with TJSONObject.create4(rest) do begin writeln('display_name: '+getstring('display_name')); free; end; free; //ApiDown end;
res back_: Coords: lat 46.62084 lng 5.43424 :Bonnaud, Val-Sonnette, Lons-le-Saunier, Jura, Bourgogne-Franche-Comté, France métropolitaine, 39190, France importance: 0.7350
Pic: 93_mX4mapbox_osm_bonnaud_referencemap.jpg
Exception: TJSONObject["status--\u0020You\u0020must\u0020enable\u0020Billing\u0020on\u0020the\u0020Google\u0020Cloud\u0020Project\u0020at\u0020https\u003A//\u0020Learn\u0020more\u0020at\u0020https\u003A//"] 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(''+ fAddr+'&country='+fcountry+'&api_key='+API_KEY) else Url:= urlid.URLEncode(''+ 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;; end; end;
writeln(TAddressGeoCoding4('Halifax','Canada')); display_name: Halifax, Halifax Regional Municipality, Halifax County, Nova Scotia, Canada debug hash 7861896 Coordinates: lat 44.649 lng -63.586 :CanVec+ by Natural Resources Canada
jo:= TJSONObject.Create4(wdc_WinInet_HttpGet2(Url,Nil));


Geocoding topics and Script




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.