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. 【BZOJ】1655: [Usaco2006 Jan] Dollar Dayz 奶牛商店(背包+高精度)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1655 背包就没什么好说的了,裸的完全背包.. 但是我一开始交开了ull都wa了T_T.. 精度太大. ...

  2. HDU 1284 钱币兑换问题(全然背包:入门题)

    HDU 1284 钱币兑换问题(全然背包:入门题) http://acm.hdu.edu.cn/showproblem.php?pid=1284 题意: 在一个国家仅有1分,2分.3分硬币,将钱N ( ...

  3. [转]Tcpcopy简介与实战

    Tcpcopy简介 TCPCopy是一种请求复制(所有基于tcp的packets)工具 ,其功能是复制在线数据包,修改TCP/IP头部信息,发送给测试服务器,达到欺骗测试服务器的TCP 程序的目的,从 ...

  4. C# 导出Excel "正在中止线程" 错误

    导出Excel相信很多人都用过,但是我却遇到了一个问题 “正在中止线程” 源代码如下: public static void ExportExcel(string fileName, GridView ...

  5. 论坛模块_版块管理_增删改查&实现上下移动

    论坛模块_版块管理1_增删改查 设计实体Forum.java public class Forum { private Long id; private String name; private St ...

  6. iOS开发之--打印一堆奇怪东西的解决方案

    Xcode8总是打印一堆奇怪的东西.虽然不影响开发,但是看着很不爽.解决的方法就是在Scheme里面添加(name):OS_ACTIVITY_MODE (value):disable 然后再在突出的框 ...

  7. 了解 IMyInterface.Stub

    Service中的IBinder 还记得我们在MyService中利用new IMyInterface.Stub()向上转型成了IBinder然后在onBind方法中返回的.那我们就看看IMyInte ...

  8. iOS 7 SDK: 如何使用后台获取(Background Fetch)

    本文转载至 http://www.cocoachina.com/applenews/devnews/2013/1114/7350.html 本文主要教你如何使用iOS 7 SDK多任务处理API--B ...

  9. cocos2dx游戏--三国关羽传【角色扮演类】Demo的制作及实现

    项目地址:https://github.com/moonlightpoet/GuanYuZhuan 主要类及其对应效果: MainScene:菜单界面(用于选择不同剧本) StoryScene:故事界 ...

  10. php做图片上传功能

    今天来做一个图片上传功能的插件,首先做一个html文件:text.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transition ...