我正在嘗試Google的Geo柵欄示例項目。我正確地獲取進入/退出事件。但是我怎樣才能從中獲得用戶的當前位置。即使在進入/退出點之後,我也想跟蹤用戶的位置。請幫忙。 The sample project is from the developer portal.從geo fence示例項目獲取當前位置
0
A
回答
0
您需要以正常方式從Fused Location Provider獲取用戶位置。完整的教程是在這裏:http://developer.android.com/training/location/retrieve-current.html
但基本上,當你收到你的接收器或服務中的地理圍欄事件,得到的LocationClient
實例有,連接到它,並在回調,onConnected()
,獲得最後已知的位置:
Location position = locationClient.getLastLocation();
99.9%的時間,或者更好一點,你會發現這個位置在你的地理圍欄內。
要繼續跟蹤用戶的位置更新,按照接收位置更新:在您的broadcastrecievero或服務http://developer.android.com/training/location/receive-location-updates.html
2
你得到一個GeofencingEvent,用它來獲得觸發位置
public class GeofenceTransitionsIntentService extends IntentService {
//[...]
@Override
protected void onHandleIntent(Intent intent) {
GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);
if (geofencingEvent.hasError()) {
// ...
}
Location l = geofencingEvent.getTriggeringLocation()
}
//[...]
}
相關問題
- 1. Viewpager:獲取當前項目位置
- 2. 獲取學位從當前位置到目標位置Android
- 3. 獲取當前位置
- 4. xcode示例項目「CurrentAddress」:當前位置來自哪裏?
- 5. Android獲取當前GEO座標
- 6. 獲取當前位置
- 7. 獲取當前位置ImageView
- 8. 需要獲取當前位置和目標位置PIN碼
- 9. CLLocation當前位置獲取位置
- 10. 從AppDelegate獲取當前位置
- 11. 從react-router-redux獲取當前位置
- 12. 從java的DataInputStream獲取當前位置
- 13. 從GPS獲取當前位置
- 14. 獲取當前位置
- 15. 獲取當前位置
- 16. 獲取當前位置android
- 17. Android獲取當前位置
- 18. android獲取當前位置
- 19. 從QMutableListIterator獲取當前項目
- 20. 從「當前項目」的類路徑位置讀取文件
- 21. 從ListView中的項目獲取位置
- 22. Roslyn:獲取當前項目/獲取當前選中的文檔
- 23. 從我的當前位置獲取距離最近的位置
- 24. 如何從位置管理器獲取當前位置?
- 25. 根據當前位置和總項目獲取當前頁面上的項目數量
- 26. angular-google-maps從鼠標點擊獲取GEO位置
- 27. 如何獲取當前位置
- 28. 獲取當前位置兩次
- 29. 從Visual Studio 2010的實驗實例獲取當前項目目錄?
- 30. 在地圖上獲取當前位置
嗨,只是清除我的困惑是否意味着如果我使用geofencing,我不必使用網絡或gps跟蹤用戶位置? Geofence自己呢? – 2014-09-30 05:25:08
正確。 Geofence可以爲你工作。 – TonyC 2014-10-10 14:07:35
locationClient.getLastLocation()返回當前位置,而不是一個觸發事件(它們接近但不相同),GeofencingEvent.getTriggeringLocation()已經存在,沒有使用已棄用的LocationClient – Zorb 2014-12-10 20:15:27