【问题标题】:Firemonkey: How can I open native IOS maps from my app?Firemonkey:如何从我的应用程序中打开本机 IOS 地图?
【发布时间】:2016-11-04 10:37:18
【问题描述】:

我需要做的只是打开并向IOS原生地图发送一个字符串。该字符串包含地址。

我发现这段代码在 android 上可以正常工作,但在 IOS 上就不行,为什么?

function OpenNavigation(const Q: string; const Coord: TLocationCoord2D): Boolean;
var
  CoordString: String;
begin
  //Open in Google Maps
  {$IFDEF ANDROID}
  exit(OpenURL('http://maps.google.com/?q=' + Q));
  {$ELSE}

  //In iOS, if Google Maps is installed, use it, otherwise, use Apple Maps
  //If we have coordinates, use them as the start address
  {$IFDEF IOS}
  exit(OpenURL('http://maps.apple.com/?daddr=' + Q));
  //Get a string of the longitute and latitute seperated by a comma if set
  if (Coord.Latitude <> 0.0) or (Coord.Longitude <> 0.0) then
  begin
    CoordString := Coord.Latitude.ToString + ',' + Coord.Longitude.ToString;
  end
  else begin
    CoordString := '';
  end;
  if not OpenURL('comgooglemaps://?daddr=' + Q) then
  begin
    if (0.0 < CoordString.Length) then
    begin
      exit(OpenURL('http://maps.apple.com/?daddr=' + Q + '&saddr=loc:' + CoordString));
    end
    else begin
      exit(OpenURL('http://maps.apple.com/?daddr=' + Q));
    end;
  end
  else begin
    exit(true);
  end;
  {$ELSE}
  //Unsupported platform
  exit(false);
  {$ENDIF IOS}
  {$ENDIF ANDROID}
end;

编辑:我使用的版本是 RadStudio 10.1 Berlin

EDIT²:我将标签“字典”两次更改为“地图”,但改回字典 idk 为什么。

【问题讨论】:

    标签: ios dictionary firemonkey


    【解决方案1】:

    要从另一个 iOS 应用打开地图应用,您可以执行以下操作:

    UIApplication.sharedApplication().openURL(NSURL(string: "http://maps.apple.com/?address=yourAddressHere")!)
    

    您还可以使用CLGeocoder 获取CLLocation 位置

    请查看此stack overflow's answer 了解更多详情。

    【讨论】:

    • 谢谢老兄,但这段代码在 Firemonkey 上不起作用,我猜这是 Swift。还是谢谢...
    • 我没有使用 FireMonkey 的经验,但可能你可以更改 url 来访问地图,并使用“maps.apple.com/?address=yourAddressHere”也可以看看这个stackoverflow.com/questions/23877683/…
    • 没用。我不知道该怎么办了,我在互联网上找不到答案。这令人沮丧……
    【解决方案2】:

    我找到了答案:

    OpenURL('http://maps.apple.com/?daddr=YourAddress');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-08
      • 1970-01-01
      • 2017-12-19
      • 2018-07-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多