Blog
All Blog Posts | Next Post | Previous PostFree (Reverse)Geocoding with OpenStreetMap Nominatim in TMS FNC Maps
Thursday, October 14, 2021
TMS FNC Maps v2.2 now includes a new free geocoding service in addition to the existing supported geocoding services from Azure, Bing, Google, Here and MapBox.
OpenStreetMap Nominatim
The OpenStreetMap Nominatim API service provides geocoding and reverse geocoding free of charge and does not require an API key. This service can be used in combination with all supported mapping services in TMS FNC Maps. Specifically in combination with the OpenLayers mapping service this is a worthwhile free alternative to comparable paying services.
Geocoding
A geocoding request converts a text address to a latitude & longitude coordinate. The coordinate can then be used to display a location on the map.
With the following code we are going to look up the location of "Baker Street, London" and display it on the center of the map with a marker and a title that contains the address.
Note that this example uses the asynchronous method with a callback.
procedure TForm1.Button1Click(Sender: TObject); var Item: TTMSFNCGeocodingItem; begin TMSFNCGeocoding1.Service := gsOpenStreetMap; TMSFNCGeocoding1.GetGeocoding('Baker Street, London', procedure(const ARequest: TTMSFNCGeocodingRequest; const ARequestResult: TTMSFNCCloudBaseRequestResult) begin if (ARequestResult.Success) and (ARequest.Items.Count > 0) then begin Item := ARequest.Items[0]; TMSFNCMaps1.BeginUpdate; TMSFNCMaps1.SetCenterCoordinate(Item.Coordinate.ToRec); TMSFNCMaps1.AddMarker(Item.Coordinate.ToRec, Item.Address); TMSFNCMaps1.EndUpdate; end; end ); end;
Reverse Geocoding
A reverse geocoding request converts a latitude & longitude coordinate to a text address. The text address can then be used to display an address associated with a location on the map.
With the following code we are going to track a click on the map, retrieve the address for that location and display it on the map with a marker and a title that contains the address
Note that this example uses the synchronous method that provides an immediate result without a callback.
procedure TForm1.TMSFNCMaps1MapClick(Sender: TObject; AEventData: TTMSFNCMapsEventData); var Address: string; begin TMSFNCGeocoding1.Service := gsOpenStreetMap; Address := TMSFNCGeocoding1.GetReverseGeocodingSync(AEventData.Coordinate.ToRec); TMSFNCMaps1.BeginUpdate; TMSFNCMaps1.SetCenterCoordinate(AEventData.Coordinate.ToRec); TMSFNCMaps1.AddMarker(AEventData.Coordinate.ToRec, Address); TMSFNCMaps1.EndUpdate; end;
Available Now
The TMS FNC Maps v2.2 update is available now for Delphi & Visual Studio Code (with TMS WEB Core). You can download the latest version and start using the new features right away!
Bart Holvoet
This blog post has received 4 comments.
AlAradi Mohamed
One thing ist still missing, a free directions service.
Is it possible with open street map/ openrouteservice.org?
Carstensen Dirk
Bart Holvoet
All Blog Posts | Next Post | Previous Post
Olivier Dehorter