如何使用RAD Studio FireMonkey在iOS和Android上启动导航应用程序?

我知道我可以使用像maps.apple.com/?q=Firehouse+Subs这样的URL 以编程方式在iOS 6中打开地图应用程序 ,但是如何才能使用FireMonkey工作呢? 我可以把它放到WebBrowser中,但它只是显示Google Maps的Web界面。 另外我知道这不适用于Android,但我可以使用意图来处理,但FireMonkey似乎也没有公开。

更新:进一步的研究表明,这可能暂时是不可能的,即使我写了一些平台特定的代码。 这个答案表明,如果不涉及Java,intent是无法被解雇的。 是否还有一种方法可以通过C ++将URL发送到iOS来打开导航? 我没有太多的iOS开发经验。

所以事实certificate,URL是两个操作系统的答案。 我能够通过一些辅助函数发送一个URL到操作系统来打开导航。 我在这里find了这个源代码。 它是用Delphi编写的,但事实certificate,你可以将Delphi文件添加到你的项目中,在你的C ++中编译#include“filename.hpp”,并使用你在Delphi中创build的函数。

 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. 

最后一个function是我添加的。 它会根据操作系统打开地图应用程序,并可select使用一组坐标来浏览,如果使用苹果地图,因为它不能像谷歌地图一样处理。 如果有人愿意,我还无法在iOS上testingGoogle地图,请告诉我。

 #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); } 

我希望上面的代码将帮助你。 它在我的应用程序上工作。 只要记住把你想要导航的地方,而不是曼彻斯特..它可以是一个邮政编码或地方,或者如果你想,你可以传递纬度和态度之后,地理而不是0,0