如何使用RAD Studio FireMonkey在iOS和Android上启动导航应用程序?
我知道我可以使用像如何使用RAD Studio FireMonkey在iOS和Android上启动导航应用程序?,ios,delphi,firemonkey,Ios,Delphi,Firemonkey,我知道我可以使用像maps.apple.com/?q=Firehouse+Subs这样的URL,但是我怎样才能让FireMonkey使用它呢?我可以把它放进网络浏览器,但它只显示谷歌地图的网络界面。我也知道这对Android不起作用,但我可以用意图来处理它,但FireMonkey似乎也没有公开这一点 更新:进一步的研究表明,即使我编写了一些特定于平台的代码,这在目前可能是不可能的。表示在没有Java参与的情况下无法激发意图。是否还有一种方式可以将URL用C++发送到iOS来打开导航?我对iOS开
maps.apple.com/?q=Firehouse+Subs
这样的URL,但是我怎样才能让FireMonkey使用它呢?我可以把它放进网络浏览器,但它只显示谷歌地图的网络界面。我也知道这对Android不起作用,但我可以用意图来处理它,但FireMonkey似乎也没有公开这一点
更新:进一步的研究表明,即使我编写了一些特定于平台的代码,这在目前可能是不可能的。表示在没有Java参与的情况下无法激发意图。是否还有一种方式可以将URL用C++发送到iOS来打开导航?我对iOS开发没有太多经验。因此,URL是两种操作系统的答案。我能够通过一些助手函数向操作系统发送URL来打开导航。我在这里的博客上找到了这个源代码。它是用Delphi编写的,但是事实证明你可以把Delphi文件添加到你的项目中,编译你的C++中包含“文件名,HPP”,并使用你在Delphi中创建的函数。
unit OpenViewUrl;
interface
uses System.Sensors;
// URLEncode is performed on the URL
// so you need to format it protocol://path
function OpenURL(const URL: string; const DisplayError: Boolean = False): Boolean;
function OpenNavigation(const Q: string): Boolean; overload;
function OpenNavigation(const Q: string; const Coord: TLocationCoord2D): Boolean; overload;
implementation
uses
IdURI, SysUtils, Classes, FMX.Dialogs
{$IFDEF ANDROID}
, FMX.Helpers.Android, Androidapi.JNI.GraphicsContentViewText,
Androidapi.JNI.Net, Androidapi.JNI.JavaTypes, Androidapi.Helpers;
{$ELSE}
{$IFDEF IOS}
, iOSapi.Foundation, FMX.Helpers.iOS, Macapi.Helpers;
{$ELSE};
{$ENDIF IOS}
{$ENDIF ANDROID}
function OpenURL(const URL: string; const DisplayError: Boolean = False): Boolean;
{$IFDEF ANDROID}
var
Intent: JIntent;
begin
// There may be an issue with the geo: prefix and URLEncode.
// will need to research
Intent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_VIEW,
//TJnet_Uri.JavaClass.parse(StringToJString(TIdURI.URLEncode(URL))));
TJnet_Uri.JavaClass.parse(StringToJString(URL)));
try
SharedActivity.startActivity(Intent);
exit(true);
except
on e: Exception do
begin
if DisplayError then ShowMessage('Error: ' + e.Message);
exit(false);
end;
end;
end;
{$ELSE}
{$IFDEF IOS}
var
NSU: NSUrl;
begin
// iOS doesn't like spaces, so URL encode is important.
// NSU := StrToNSUrl(TIdURI.URLEncode(URL));
NSU := StrToNSUrl(URL);
if SharedApplication.canOpenURL(NSU) then
exit(SharedApplication.openUrl(NSU))
else
begin
if DisplayError then
ShowMessage('Error: Opening "' + URL + '" not supported.');
exit(false);
end;
end;
{$ELSE}
begin
raise Exception.Create('Not supported!');
end;
{$ENDIF IOS}
{$ENDIF ANDROID}
function OpenNavigation(const Q: string): Boolean;
var Coord: TLocationCoord2D;
begin
Coord.Latitude := 0.0;
Coord.Longitude := 0.0;
OpenNavigation(Q, Coord);
end;
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}
//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;
end.
unitopenviewurl;
接口
使用系统传感器;
//URL编码是在URL上执行的
//所以你需要格式化它protocol://path
函数OpenURL(consturl:string;constdisplayError:Boolean=False):Boolean;
函数OpenNavigation(const Q:string):布尔值;超载;
函数OpenNavigation(const Q:string;const-Coord:TLocationCoord2D):布尔;超载;
实施
使用
IdURI、SysUtils、类、FMX.Dialogs
{$IFDEF ANDROID}
,FMX.Helpers.Android,Androidapi.JNI.GraphicsContentViewText,
Net,Androidapi.JNI.JavaTypes,Androidapi.Helpers;
{$ELSE}
{$IFDEF IOS}
,IOSAPI。基金会,FMX.HelpS.IOS,MACAPI。
{$ELSE};
{$ENDIF IOS}
{$ENDIF ANDROID}
函数OpenURL(consturl:string;constdisplayError:Boolean=False):Boolean;
{$IFDEF ANDROID}
变量
意向:金腾;
开始
//geo:prefix和URLEncode可能有问题。
//需要进行研究
Intent:=TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_视图,
//TJnet_Uri.JavaClass.parse(StringToJString(TIdURI.URLEncode(URL));
TJnet_Uri.JavaClass.parse(StringToJString(URL));
尝试
共享活动。启动活动(意图);
退出(真);
除了
关于e:Exception-do
开始
如果显示错误,则显示消息('Error:'+e.Message);
退出(假);
结束;
结束;
结束;
{$ELSE}
{$IFDEF IOS}
变量
NSU:NSUrl;
开始
//iOS不喜欢空格,所以URL编码很重要。
//NSU:=StrToNSUrl(TIdURI.URLEncode(URL));
NSU:=StrToNSUrl(URL);
如果SharedApplication.canOpenURL(NSU),则
退出(SharedApplication.openUrl(NSU))
其他的
开始
如果显示错误,则
ShowMessage('错误:打开“'+URL+”“不受支持”);
退出(假);
结束;
结束;
{$ELSE}
开始
引发异常。创建('notsupported!');
结束;
{$ENDIF IOS}
{$ENDIF ANDROID}
函数OpenNavigation(const Q:string):布尔值;
var Coord:TLocationCoord2D;
开始
坐标纬度:=0.0;
坐标经度:=0.0;
开放导航(Q,Coord);
结束;
函数OpenNavigation(const Q:string;const-Coord:TLocationCoord2D):布尔;
变量
CoordString:String;
开始
//在谷歌地图中打开
{$IFDEF ANDROID}
退出(OpenURL('http://maps.google.com/?q="Q),;
{$ELSE}
//在iOS中,如果安装了谷歌地图,请使用它,否则,请使用苹果地图
//如果我们有坐标,用它们作为起始地址
{$IFDEF IOS}
//若已设置,则获取由逗号分隔的longitute和latittute字符串
如果是(坐标纬度0.0)或(坐标经度0.0),则
开始
CoordString:=Coord.Latitude.ToString+','+Coord.Latitude.ToString;
结束
否则开始
CoordString:='';
结束;
如果不是OpenURL('comgooglemaps://?daddr='+Q),那么
开始
如果(0.0
最后一个函数是我添加的。它将根据操作系统打开地图应用程序,如果使用Apple maps,还可以选择使用一组坐标进行导航,因为它的处理能力不如Google maps。我无法在iOS上测试谷歌地图,如果有人能够,请告诉我。\include
#include <fmx.h>
#include <System.IOUtils.hpp>
#include <Androidapi.JNI.GraphicsContentViewText.hpp>
#include <Androidapi.JNI.Net.hpp>
#include <Androidapi.Helpers.hpp>
#include <FMX.Helpers.Android.hpp>
void __fastcall TForm4::Button1Click(TObject *Sender)
{
String url = "geo:0,0?q=Manchester";
_di_JIntent Intent = TJIntent::JavaClass->init(TJIntent::JavaClass->ACTION_VIEW,TJnet_Uri::JavaClass->parse(StringToJString(url)));
SharedActivity()->startActivity(Intent);
}
#包括
#包括
#包括
#包括
#包括
void\uu fastcall TForm4::按钮1单击(ToObject*发送方)
{
字符串url=“geo:0,0?q=Manchester”;
_di_JIntent Intent=TJIntent::JavaClass->init(TJIntent::JavaClass->ACTION_视图,TJnet_Uri::JavaClass->parse(StringToJString(url));
SharedActivity()->startActivity(意图);
}
我希望上面的代码能帮助你。它确实在我的应用程序上起作用。只要记住把你想导航的地方,而不是曼彻斯特。。它可以是邮政编码或地点,或者如果您愿意,您可以在地理位置后传递纬度和姿态,而不是0,0