delphi - 如何在 Delphi VCL 应用程序中显示开放街道 map 并与之交互

标签 delphi leaflet maps openstreetmap

这是一个相当广泛的问题,但我会尽力将其缩小到要点。 我正在为一个学校项目开发 Delphi 应用程序,其中我想向我的程序添加 map 以提供位置功能。我使用的是 RAD studios 10.3

由于这是一个学校项目,如果可能的话,我不想在上面花钱,我也不想使用谷歌地图,因为你需要创建一个计费帐户(我知道你仍然会收到一些免费请求)。

要求:

  • 用户可以查看动态 map 并放置图钉(不需要是永久性的)
  • 正向和反向地理编码。
  • 在 VCL 程序中使用

根据我的研究,我明白这一点: 我可以使用 Leaflet ( https://leafletjs.com/index.html ) 与 Open Streets Maps 进行交互 我必须将请求从我的 Delphi 应用程序发送到某个地方(传单?)以获取 map 和地理编码数据

  • 我使用什么组件在 vcl 表单上显示 map
  • 如何通过 Leaflet 与 Open Street Maps 互动?

(如果我能理解如何与传单之类的东西交互并且我可以访问他们的文档,那么以下问题可能是多余的)

  • 如何通过 PIN 码请求坐标和街道地址?
  • 如何显示带有 GPS 坐标中的图钉的 map ?

提前谢谢您。

最佳答案

我很久以前就使用过 Bing map 。为了加载要显示的 map ,我使用了 Indy 项目中的“TIdHTTP”。我认为它与 Leaflet 的工作方式相同。

这是我的代码:

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;

您可以在此处找到完整的法语版:
https://github.com/ILPlais/BingMapsGPS/blob/master/UBingMapsGPS.pas

关于delphi - 如何在 Delphi VCL 应用程序中显示开放街道 map 并与之交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61289615/

相关文章:

r - 在基组之间切换时是否可以在多个图例之间切换?

javascript - LeafLet绘制,标记层无法点击

javascript - 如何在 OpenLayers 中相互独立地移动两个图层?

delphi - 如何将http下载图像从扩展转换为另一个?

delphi - 记录后我应该如何重新引发 Delphi 异常?

delphi - delphi创建表单时出错

r - 传单标签重叠修复 - leaflet::addMarkers

angular - 调用传单标记的 onClick 时 Material 对话框卡住

delphi - XML-RPC 和 Delphi 遇到问题

google-maps - Flutter无法解码图像。提供的图像必须是位图。