4

This is a rather broad question but I will try to narrow it down to the essentials. I am working on a Delphi Application for a school project wherein I would like to add a map to my program to provide location functionality. I am using RAD studios 10.3

As this is a school project I would not like to spend money on it if possible, I would also not like to use google maps as you need to make a billing account(I know you do get some free requests still).

Requirements:

  • user can view a dynamic map and place pins(do not need to be permanent)
  • forward and reverse geocoding.
  • use within a VCL program

From my research I Understand This : I can use Leaflet (https://leafletjs.com/index.html) to interact with Open Streets Maps I will Have to send requests from my Delphi application to somewhere(Leaflet?) to get map and geoCoding data

  • what component do I use to display the maps on my vcl form
  • How do I interact with Open Street Maps through Leaflet?

(these following questions may be redundant if I can understand how to interact with something like leaflet and I have access to their documentation)

  • How do I request co-ords and street address from a pin?
  • How do I show a map with a pin from GPS Coords?

Thank you in advance.

6
  • 1
    Leaflet is a JavaScript library. If you want to use it, you will have to embed a browser in your app (you can use TWebBrowser for that).
    – Olivier
    Commented Apr 18, 2020 at 13:51
  • 1
    @Olivier Ok that makes sense. I don't know javascript but I'm willing to learn. Can you explain or refer me to how I can communicate between my program and leaflet with Java script? Commented Apr 18, 2020 at 15:23
  • 1
    @CL. Thank you those are some useful resources Commented Apr 18, 2020 at 15:24
  • 1
    Your program can't directly communicate with JS. However the Delphi program can access the HTML page and do a number of things; see here and there for examples.
    – Olivier
    Commented Apr 18, 2020 at 16:24
  • 2
    @Olivier thanks for pointing me in the right direction, I am making progress Commented Apr 19, 2020 at 19:30

1 Answer 1

0

I worked a long time ago with Bing Maps. And to load the map to display, I used a `TIdHTTP' from the Indy Project. I think it would work the same way with Leaflet.

Here's my code:

const
  // Place here the key retrieved from the site Bing Maps Account Center
  Key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
  Server = 'http://dev.virtualearth.net/REST/v1/';
  URLPicFormat = Server + 'Imagery/Map/%s/%s,%s/%d?ms=%d,%d&pp=%s,%s;6&key='
    + Key;
var
  Address, Map, LatStr, LongStr, TypeView: String;
  Response: TFileStream;
begin
  {...}
  // Don't forget to add the JPEG unit
  Map     := WindowsTempDir + 'Map.jpeg';

  // Format the URL for the picture to load
  Address := Format(URLPicFormat, [TypeView, LatStr, LongStr,
    TB_Zoom.Position, IMG_Map.Width, IMG_Map.Height, LatStr, LongStr]);

  // Load the picture from Bing Maps
  Response := TFileStream.Create(Map, fmCreate);
  try
    HTTP_BingMaps.Get(Address, Response);
  finally
    Response.Free();
  end;
  IMG_Map.Picture.LoadFromFile(Map);
  {...}
end;

You can find the full unit here in French:
https://github.com/ILPlais/BingMapsGPS/blob/master/UBingMapsGPS.pas

1
  • Hey thanks for the answer, I think I used a slightly different method, but thanks for sharing. Commented Apr 28, 2020 at 18:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.