全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1181
推到 Plurk!
推到 Facebook!

FM 的 GPS LOCATION

答題得分者是:QCom Support
P.D.
版主


發表:603
回覆:4038
積分:3874
註冊:2006-10-31

發送簡訊給我
#1 引用回覆 回覆 發表時間:2014-07-31 02:44:49 IP:118.160.xxx.xxx 未訂閱
請問各位:

以下的程式, 可以順利取得 GPS 位置, 但有一個疑問
LocationSensor 開啟後, 我只想取一筆記錄(而不是取連串的路徑), Active 是否要關閉,
因為如果我在最後面加入 LocationSensor1.Acitve := False
手機就會引發錯誤 Java.Lang.lllegalArgrmentException: Invalid listener: null
要如何解決, 還是 Sensor 會自動關閉(我想應該不是)

LocationSensor1.Active := True;
if FTimeService <> nil then begin
bTime := FTimeService.GetTick;
eTime := bTime;
while eTime - bTime <= 5000 do begin
eTime := FTimeService.GetTick;
if (U_Util.gpsx<>'') and (U_Util.gpsy<>'') then break;
end;
end;
QCom Support
一般會員


發表:15
回覆:32
積分:24
註冊:2012-12-17

發送簡訊給我
#2 引用回覆 回覆 發表時間:2014-08-01 14:17:16 IP:61.219.xxx.xxx 訂閱
您好:

請問程式中的 FTimeService 是什麼? 可以請您詳述一下您的專案

謝謝!
P.D.
版主


發表:603
回覆:4038
積分:3874
註冊:2006-10-31

發送簡訊給我
#3 引用回覆 回覆 發表時間:2014-08-02 00:48:55 IP:220.136.xxx.xxx 未訂閱
目前我測試的結果, 我把 Location.onchanged 上加入try except, 然後下 location1.acitve := False 就不會引發 Java 的錯誤, 不過想了解造成的原因
try
... 取得gps 資料
except
end;
P.D.
版主


發表:603
回覆:4038
積分:3874
註冊:2006-10-31

發送簡訊給我
#4 引用回覆 回覆 發表時間:2014-08-05 00:26:15 IP:220.136.xxx.xxx 未訂閱
已找到可能的問題(我猜的啦)

在 Location on Changed 事件

begin
try
label1.caption := NewLocation.Latitude.ToString;
label2.caption := NewLocation.Longitude.ToString;
except
end;
end;

或者
begin
if NewLocation.Latitude * NewLocation.Longitude > 0 then begin
label1.caption := NewLocation.Latitude.ToString;
label2.caption := NewLocation.Longitude.ToString;
end;
end;

因為要取出 經緯度, 網路上普遍使用 tostring 的用法, 而 Latitude 是 Double ,
當我們下 Location1.Acitve := False 時, 可能還會再觸發 onChanged, 但此時的 Latitude 內存值不知道是什麼內容, 導致 tostring 發生錯誤,

以上是我猜想可能的原因, 沒有時間進行驗證, 但以上兩者方法都可以避開 error 就好了
編輯記錄
P.D. 重新編輯於 2014-08-05 00:27:39, 註解 無‧
test28
一般會員


發表:28
回覆:28
積分:16
註冊:2013-08-26

發送簡訊給我
#5 引用回覆 回覆 發表時間:2014-08-08 21:49:35 IP:101.14.xxx.xxx 未訂閱
我也遇到相同狀況,但xe6不會,xe6 up1才會?
謝謝提供兩個方法,但這兩個方法在我這邊都還會發生相同狀況,不知為何?

===================引 用 P.D. 文 章===================
已找到可能的問題(我猜的啦)

在 Location on Changed 事件

begin
try
label1.caption := NewLocation.Latitude.ToString;
label2.caption := NewLocation.Longitude.ToString;
except
end;
end;

或者
begin
if NewLocation.Latitude * NewLocation.Longitude > 0 then begin
label1.caption := NewLocation.Latitude.ToString;
label2.caption := NewLocation.Longitude.ToString;
end;
end;

因為要取出 經緯度, 網路上普遍使用 tostring 的用法, 而 Latitude 是 Double ,
當我們下 Location1.Acitve := False 時, 可能還會再觸發 onChanged, 但此時的 Latitude 內存值不知道是什麼內容, 導致 tostring 發生錯誤,

以上是我猜想可能的原因, 沒有時間進行驗證, 但以上兩者方法都可以避開 error 就好了
P.D.
版主


發表:603
回覆:4038
積分:3874
註冊:2006-10-31

發送簡訊給我
#6 引用回覆 回覆 發表時間:2014-08-13 23:28:07 IP:118.169.xxx.xxx 未訂閱
我沒有測試xe6(已經是upd1), 
後來我再試, 有時還是會出現錯誤, 所以我再包了一層, 這樣就不會了!

try
Location1.Active:= false
except
end;
===================引 用 test28 文 章===================
我也遇到相同狀況,但xe6不會,xe6 up1才會?
謝謝提供兩個方法,但這兩個方法在我這邊都還會發生相同狀況,不知為何?

===================引 用 P.D. 文 章===================
已找到可能的問題(我猜的啦)

在 Location on Changed 事件

begin
try
label1.caption := NewLocation.Latitude.ToString;
label2.caption := NewLocation.Longitude.ToString;
except
end;
end;

或者
begin
if NewLocation.Latitude * NewLocation.Longitude > 0 then begin
label1.caption := NewLocation.Latitude.ToString;
label2.caption := NewLocation.Longitude.ToString;
end;
end;

因為要取出 經緯度, 網路上普遍使用 tostring 的用法, 而 Latitude 是 Double ,
當我們下 Location1.Acitve := False 時, 可能還會再觸發 onChanged, 但此時的 Latitude 內存值不知道是什麼內容, 導致 tostring 發生錯誤,

以上是我猜想可能的原因, 沒有時間進行驗證, 但以上兩者方法都可以避開 error 就好了
系統時間:2024-04-20 15:52:21
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!