示範如果快速使用Delphi XE4開發iOS定位功能的程式
1.建立一個新的FireMonkey Mobile Application

2.選擇 Blank Application 空白類型。

3.新增元件ListBox,將 Align 改為 alTop; GroupingKind 改為 GsGrouped;StyleLookup 改為 transparentlistboxstyle。

4. ListBox按右鍵,Add Item 新增 TListBoxHeader,在裡面新增Label ,屬性 Align 設為 alClient ; StyleLookup 設為 toollabel ; TextAlign 設為 taCenter。

5. 接著新增三個 TListBoxItem,分別是開啟定位、經度、緯度。在開啟定位的右側新增TSwitch開關來開啟定位功能。經度、緯度使用TLabel。


6.接著在畫面上佈置TWebBrowser跟TLocationSensor,TWebBrowser的 Align 設為 alClient。


7.佈置好的畫面如下圖

8. 在Switch1 的 OnSwitch 事件中新增程式如下
[delphi]
procedure TForm1.Switch1Switch(Sender: TObject);
begin
LocationSensor1.Active := Switch1.IsChecked ;
end;
[/delphi]
9.接著在 LocationSensor1 的 OnLocationChange事件中新增程式如下
[delphi]
procedure TForm1.LocationSensor1LocationChanged(Sender: TObject;
const OldLocation, NewLocation: TLocationCoord2D);
const
sGoogleMapURL : String = ‘https://maps.google.com/maps?q=%s,%s&output=embed’;
begin
label3.Text := ‘經度: ‘ + NewLocation.Latitude.ToString;
label2.Text := ‘緯度: ‘ + NewLocation.Longitude.ToString;
WebBrowser1.Navigate(Format(sGoogleMapURL,
[NewLocation.Latitude.ToString,
NewLocation.Longitude.ToString]));
end;
[/delphi]
10.大功告成!我們來看執行結果

