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. 下列哪个为JSP的小脚本的标签?(选择1项)

    下列哪个为JSP的小脚本的标签?(选择1项) A.<% %> B.<@ %> C.<%! %> D.<%– %> 解答:A

  2. Spring HttpIvoker实现Java的远程调用

    Spring HttpInvoker一种JAVA远程方法调用框架实现,使用的是HTTP协议,允许穿透防火墙,使用JAVA系列化方式,但仅限于Spring应用之间使用,即调用者与被调用者都必须是使用Sp ...

  3. 配置gosublime

    Installation Sublime Package Control allows you to easily install or remove GoSublime (and many othe ...

  4. es6 javascript的class的静态方法、属性和实例属性

    http://blog.csdn.net/qq_30100043/article/details/53542966

  5. C语言位运算+实例讲解(转)

    按位或 按位与 按位异或 按位取反 左移右移 C语言位运算 有6种: &, | , ^(亦或), >(右移). 注意:参与位运算的元素必须是int型或者char型,以补码形式出现. 按位 ...

  6. vue2.0中,由于页面完成之后dom还未加载完成如何进行操作

    再vue中,当页面加载完成以后,dom还没有加载,是无法获取进行操作的,但是在vue2.0中提供了一个方法:this.$nextTick,在这个回调函数里面写dom操作即可: 如下代码: create ...

  7. 使用javascript来访问本地文件夹

    常用的.net 的aspx文件由于运行在服务器端,并不具有访问用户本地文件夹的权限,导致类似于<a href="file:///d:/backup" > open fo ...

  8. python中的各种符号

    在这里所作的是将所有的 Python 符号和关键字列出来,这些都是值得掌握的重点. 关键字  and  del  from  not  while  as  elif  global ...

  9. 妙味,结构化模块化 整站开发my100du

    ********************************************************************* 重要:重新审视的相关知识 /* 妙味官网:www.miaov ...

  10. 飘城旅游网pc,流式,响应式布局

    相关视频教程http://pan.baidu.com/s/1o77wirK 我的源码链接:http://pan.baidu.com/s/1czTsKI