Blog

All Blog Posts  |  Next Post  |  Previous Post

Free (Reverse)Geocoding with OpenStreetMap Nominatim in TMS FNC Maps

Bookmarks: 

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

TMS Software Delphi  Components

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.

TMS Software Delphi  Components

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.

TMS Software Delphi  Components

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


Bookmarks: 

This blog post has received 4 comments.


1. Thursday, October 14, 2021 at 9:19:54 AM

GREAT, Youpie, Bravo

Olivier Dehorter


2. Thursday, October 14, 2021 at 5:04:30 PM

Nice!!

AlAradi Mohamed


3. Tuesday, October 19, 2021 at 11:32:06 AM

Perfect, thank''s!
One thing ist still missing, a free directions service.
Is it possible with open street map/ openrouteservice.org?

Carstensen Dirk


4. Tuesday, October 19, 2021 at 11:38:36 AM

Support for the OpenRouteService.org directions API is planned for a future release of TMS FNC Maps! 😉

Bart Holvoet




Add a new comment

You will receive a confirmation mail with a link to validate your comment, please use a valid email address.
All fields are required.



All Blog Posts  |  Next Post  |  Previous Post