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.
  • Latitude: 38°28'45" N Longitude: 22°29'36" E
  • Elevation above sea level: 560 m = 1837 ft


So how I did this? With the OpenStreetMap API Nominatim.

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.


Geocoding (also known as forward geocoding) allows you to convert one or more addresses into geographic coordinates (i.e. latitude and longitude). Geocoding will also parse the address and append additional information (e.g. if you specify a zip code, Geocodio will return the city and state corresponding zip code as well).

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));


Geocoded locations expressed in latitude, longitude coordinates can be obtained one at a time in web maps such as OSM, Geocodio, Bing Maps or Google Maps. Reverse geocoding is the process of converting latitude and longitude into a street address. The relative ease of geocoding and resulting accuracy can vary widely depending on a number of factors. What is the nature or the source of the data? How accurate is it and what format is it in? What geocoding technique will be used like REST or batch or scripts? Determining a geocoding strategy that best suits a particular need is not always clear.

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