我需要做的就是打开并向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为什么。
答案 0 :(得分:1)
要从其他iOS应用中打开Maps App,您可以执行以下操作:
UIApplication.sharedApplication().openURL(NSURL(string: "http://maps.apple.com/?address=yourAddressHere")!)
您还可以使用CLGeocoder
获取CLLocation
位置信息
请查看此stack overflow's answer了解详情。
答案 1 :(得分:0)
我找到了答案:
OpenURL('http://maps.apple.com/?daddr=YourAddress');