Tuesday, October 4, 2011

Getting directions from an iOS FireMonkey application

Q: How do you get directions on the iPhone from a FireMonkey application?
A: By opening a URL formatted like so - http://maps.google.com/maps?saddr=FROM&daddr=TO

unit Unit1;

{$IFDEF FPC}
{$mode objfpc}{$H+}
{$modeswitch objectivec1}
{$ENDIF}

interface

uses
SysUtils, Types, UITypes, Classes, Variants, FMX_Types, FMX_Controls, FMX_Forms,
FMX_Dialogs
{$IFDEF FPC}
, iPhoneAll
{$ENDIF}
;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.lfm}

procedure TForm1.Button1Click(Sender: TObject);
var
LocationFrom, LocationTo, URL : String;
begin
{$IFDEF FPC}
LocationFrom := 'Current+Location';
LocationTo := 'Scotts+Valley+Drive,+Scotts+Valley,+CA';
URL := 'http://maps.google.com/maps?saddr='+LocationFrom+'&daddr='+LocationTo;
UIApplication.sharedApplication.openUrl(NSUrl.URLWithString(NSSTR(PChar(URL)))));
{$ENDIF}
end;

end.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.