Delphi APP 開發入門(五)GPS 定位功能

閲讀次數:3518 發表時間:2014/06/03

Delphi APP 開發入門(四)簡易手電筒 << 前情

在行動裝置的應用上,大多會離不開GPS定位以及地圖功能。今天就來教大家製作一個簡易的定位結合地圖的APP-「我現在在那裡」,讀者們可以利用這個超級簡單的APP延伸進階成其他的應用。

一、開啟一個新的Mobile專案

二、在畫面上放置一個ListBox元件,屬性設定如下

Align : Top

GroupingKind : Grouped

StyleLookup: ListboxStyle

       

    

三、接著我們要在上面增加一個程式的抬頭,在ListBox按右鍵,Add Item -> TListBoxHeader。接著在ListBoxHeader上新增一個Label,把屬性設定如下

Align : Client

StyleLookup: toollabel

Text: 我現在在那裡

TextSettings->HorzAlign: Center

    

四、接著在畫面上設定定位功能的開關跟顯示經緯度,一樣在Listbox上右鍵Add Item -> TListBoxItem建立三次。修改每個ListBoxItem的Text屬性為開啟定位功能、經度、緯度。   

五、在上面放上TSwitch跟Label元件如下。

六、接著要顯示Google 地圖,在畫面上放置TWebBrowser元件,把Align設為Client。

七、最後在畫面上放上LocationSensor元件即完成畫面佈置。

八、正式開始寫程式囉!需要寫程式的地方只有二個,一個是打開LocationSensor定位,另一個是顯示在地圖上。在Switch的OnSwitch事件中,輸入以下程式

procedure TForm1.Switch1Switch(Sender: TObject);
begin
LocationSensor1.Active := Switch1.IsChecked;
end;

九、接著在LocationSensor的OnLocationChanged事件輸入以下程式

procedure TForm1.LocationSensor1LocationChanged(Sender: TObject;
const OldLocation, NewLocation: TLocationCoord2D);
const
sGoogleMapURL : String = 'https://maps.google.com/maps?q=%s,%s';
begin
label2.Text := NewLocation.Latitude.ToString;
label3.Text := NewLocation.Longitude.ToString;
WebBrowser1.Navigate(Format(sGoogleMapURL,
[NewLocation.Latitude.ToString,
NewLocation.Longitude.ToString]));
end;

十、接著可以執行了!這邊是透過iOS模擬器執行的,如果要看到動態變動經緯度的效果,可以在模擬器的Debug -> Location ->設定成 City Run就會自動變動位置了。


本文章程式碼下載 >> GitHub

這幾個禮拜下來,是不是覺得Delphi的開發時間大部份都是在拖拖拉拉畫面中渡過呢?培養了興趣之後,下週我們要開始回歸到比較嚴肅的基本語法課程囉 

後續 >> Delphi APP 開發入門(六)Object Pascal 語法初探

Delphi APP 開發入門(五)GPS 定位功能的更多相关文章

  1. Delphi APP 開發入門(六)Object Pascal 語法初探

    Delphi APP 開發入門(六)Object Pascal 語法初探 分享: Share on facebookShare on twitterShare on google_plusone_sh ...

  2. Delphi APP 開發入門(八)SQLite資料庫

    Delphi APP 開發入門(八)SQLite資料庫 分享: Share on facebookShare on twitterShare on google_plusone_share   閲讀次 ...

  3. Delphi APP 開發入門(七)通知與雲端推播

    Delphi APP 開發入門(七)通知與雲端推播 分享: Share on facebookShare on twitterShare on google_plusone_share   閲讀次數: ...

  4. Delphi APP 開發入門(四)簡易手電筒

    Delphi APP 開發入門(四)簡易手電筒 分享: Share on facebookShare on twitterShare on google_plusone_share   閲讀次數:32 ...

  5. Delphi APP 開發入門(十)REST Client 開發

    Delphi APP 開發入門(十)REST Client 開發 分享: Share on facebookShare on twitterShare on google_plusone_share ...

  6. Delphi APP 開發入門(九)拍照與分享

    Delphi APP 開發入門(九)拍照與分享 分享: Share on facebookShare on twitterShare on google_plusone_share   閲讀次數:30 ...

  7. Delphi APP 開發入門(三)簡易計算機

    Delphi APP 開發入門(三)簡易計算機 分享: Share on facebookShare on twitterShare on google_plusone_share   閲讀次數:68 ...

  8. Delphi APP 開發入門(二)Android/iOS設定,Hello World

    Delphi APP 開發入門(二)Android/iOS設定,Hello World 分享: Share on facebookShare on twitterShare on google_plu ...

  9. Delphi APP 開發入門(一)重生的 Delphi

    Delphi APP 開發入門(一)重生的 Delphi 分享: Share on facebookShare on twitterShare on google_plusone_share   閲讀 ...

随机推荐

  1. UDP也需要现有Server端,然后再有Client端

    UDP编程: DatagramSocket(邮递员):对应数据报的Socket概念,不需要创建两个socket,不可使用输入输出流. DatagramPacket(信件):数据包,是UDP下进行传输数 ...

  2. 【NOIP模拟题】Incr(dp)

    太水的dp没啥好说的.. #include <cstdio> #include <cstring> #include <cmath> #include <st ...

  3. js中的问题(this)(遍历对象中的属性)

    for (var i in this) { if (this[i] == null) this[i] = "";//属性如果为null,则默认为"";      ...

  4. PHP项目中经常用到的无限极分类函数

    //无限极分类函数调用 function getTree($data,$parent_id = 0,$dept_level = 0){ static $tree = []; foreach ($dat ...

  5. 分页技巧_抽取出公共的分页用的Service方法

    分页技巧_抽取出公共的分页用的Service方法 TopicAction.java ForumAction.java 放在父类中DaoSupport.java DaoSupportImpl.java ...

  6. PagerAdapter 普通写法

    1,viewPagre的普通写法 public ImagePagerAdapter(Context context, List<Photo> imgList) { this.mContex ...

  7. php实现简单的权限管理

    今天主要来实现一个权限管理系统,它主要是为了给不同的用户设定不同的权限,从而实现不同权限的用户登录之后使用的功能不一样,首先先看下数据库 总共有5张表,qx_user,qx_rules和qx_jues ...

  8. angular4 form 表单中 input输入框的disabled属性

    直接加[disabled]="isDisabled"属性的话,出现报错 根据提示,做如下修改 private isEdit: boolean = true; private isD ...

  9. 将工程导入到SVN仓库

    1.在桌面右键点开Tortoise客户端 2.选择仓库 3.在仓库的trunk目录下为新工程创建文件夹

  10. 160613、MyBatis insert操作返回主键

    在使用MyBatis做持久层时,insert语句默认是不返回记录的主键值,而是返回插入的记录条数:如果业务层需要得到记录的主键时,可以通过配置的方式来完成这个功能,针对Sequence主键而言,在执行 ...