示範如果快速使用Delphi XE4開發iOS定位功能的程式
1.建立一個新的FireMonkey Mobile Application
![未命名 - 1](http://cdnlevin.yowauction.com/2013/05/未命名-12.jpg)
2.選擇 Blank Application 空白類型。
![未命名 - 2](http://cdnlevin.yowauction.com/2013/05/未命名-21.jpg)
3.新增元件ListBox,將 Align 改為 alTop; GroupingKind 改為 GsGrouped;StyleLookup 改為 transparentlistboxstyle。
![未命名 - 3](http://cdnlevin.yowauction.com/2013/05/未命名-31.jpg)
4. ListBox按右鍵,Add Item 新增 TListBoxHeader,在裡面新增Label ,屬性 Align 設為 alClient ; StyleLookup 設為 toollabel ; TextAlign 設為 taCenter。
![未命名 - 7](http://cdnlevin.yowauction.com/2013/05/未命名-71.jpg)
5. 接著新增三個 TListBoxItem,分別是開啟定位、經度、緯度。在開啟定位的右側新增TSwitch開關來開啟定位功能。經度、緯度使用TLabel。
![未命名 - 22](http://cdnlevin.yowauction.com/2013/05/未命名-22.jpg)
![未命名 - 15](http://cdnlevin.yowauction.com/2013/05/未命名-15.jpg)
6.接著在畫面上佈置TWebBrowser跟TLocationSensor,TWebBrowser的 Align 設為 alClient。
![未命名 - 16](http://cdnlevin.yowauction.com/2013/05/未命名-16.jpg)
![未命名 - 18](http://cdnlevin.yowauction.com/2013/05/未命名-18.jpg)
7.佈置好的畫面如下圖
![未命名 - 24](http://cdnlevin.yowauction.com/2013/05/未命名-24.jpg)
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.大功告成!我們來看執行結果
![螢幕快照 2013-05-19 上午11.16.43](http://cdnlevin.yowauction.com/2013/05/螢幕快照-2013-05-19-上午11.16.43.png)
![螢幕快照 2013-05-19 上午11.22.22](http://cdnlevin.yowauction.com/2013/05/螢幕快照-2013-05-19-上午11.22.22.png)