BlogAll Blog Posts | Next Post | Previous Post
Friday, May 21, 2021
We are back with another freebie friday!
TMS FNC Maps comes with a lot of great functionality as well as a (lesser visible) unit bundling helper functions to empower your developments. The unit is called (FMX.)TMSFNCMapsCommonTypes.pas. The prefix FMX., can be replaced with VCL., WEBLib. or LCL depending on the framework. Below are a couple of helper functions explained to help you in write your code more efficiently or add more complex functionality to your application.
Plus Codes are like street addresses for people or places that dont have one. Instead of addresses with street names and numbers, Plus Codes are based on latitude and longitude, and displayed as numbers and letters. With a Plus Code, people can receive deliveries, access emergency and social services, or just help other people find them.source: https://maps.google.com/pluscodes/
TMS FNC Maps supports Plus Codes encoding & decoding with the TTMSFNCMapsPlusCode class. To get started, and convert an existing coordinate to a Plus Code, use the following code:
procedure TForm1.EncodeCoordinate; var p: string; begin p := TTMSFNCMapsPlusCode.Encode(CreateCoordinate(40.689188, -74.044562)); //p = '87G7MXQ4+M5' end;
procedure TForm1.DecodePlusCode; var c: TTMSFNCMapsBoundsRec; begin c := TTMSFNCMapsPlusCode.Decode('87G7MXQ4+M5'); end;
Measuring distance between 2 coordinates
Another great utility function is to measure the distance (in meters) between 2 coordinates. The distance measured is based on the average earth radius (6371000 meters). The sample below demonstrates how to measure the distance between 2 coordinates, but also how to create bounds, create a circle, calculate a new coordinate based on the bearing and many more.
procedure TForm1.AddCircle; var b: TTMSFNCMapsBoundsRec; d, br: Double; c: TTMSFNCMapsCoordinateRec; I: Integer; begin b := CreateBounds(40.76437, -73.94928, 40.76799, -73.98235); d := MeasureDistance(b.NorthEast, b.SouthWest); c := CalculateCoordinate(b.NorthEast, CalculateBearing(b.NorthEast, b.SouthWest), d); TMSFNCMaps1.BeginUpdate; with TMSFNCMaps1.AddCircle(b.NorthEast, Round(MeasureDistance(b.NorthEast, b.SouthWest) / 2)) do begin FillColor := gcRed; FillOpacity := 0.5; StrokeWidth := 10; StrokeColor := gcPink; end; TMSFNCMaps1.EndUpdate; end;
This blog post has not received any comments yet.
All Blog Posts | Next Post | Previous Post