我想在Android中獲取經緯度形式的手機gps位置。我需要它的代碼?有誰能夠幫助我?我想要在android中獲得gps位置的移動設備。我需要代碼?
-4
A
回答
2
This可以提供幫助。 否則,只需在上述搜索表單中搜索Android gps位置即可。
1
使用LocationManager。
LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double longitude = location.getLongitude();
double latitude = location.getLatitude();
到getLastKnownLocation()的調用不會阻塞 - 這意味着它會返回null,如果沒有位置是當前可用 - 所以你可能想在傳遞一個LocationListener的到requestLocationUpdates看看()方法相反,它會給你的位置異步更新。
private final LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
longitude = location.getLongitude();
latitude = location.getLatitude();
}
}
lm.requestLocationUpdates(LocationManager.GPS,2000,10,locationListener);
如果您想使用GPS,你需要給你的應用程序的權限ACCESS_FINE_LOCATION:
+0
如果您想使用帶唯一Wi-Fi的LocationManager,則需要ACCESS_COARSE_LOCATION ;) – Rob013
0
相關問題
- 1. 需要android活動才能等到獲得GPS位置
- 2. 在我的Android可穿戴設備中獲取GPS位置
- 3. 在Android上需要GPS位置幫助
- 4. 想要在android活動中獲得用戶的當前位置
- 5. Android設備需要重新啓動/重新啓動GPS芯片長時間後才能獲取GPS位置
- 6. 需要在我的代碼
- 7. 在那裏我需要設置我的等待代碼
- 8. 如何獲得我想要的動畫?
- 9. 跟蹤我的設備的GPS位置
- 10. 使用片段我想要在Android中獲取當前位置
- 11. 我想要得到android
- 12. 我需要一個Python代碼,將解析線,並獲得我需要
- 13. jQuery DataTables - 我無法獲得想要的效果我想要
- 14. 我需要在所有移動設備上測試此網站
- 15. 需要幫助在代碼中設置代碼(Android開發)
- 16. 我想在Android設備上獲得的位置,但它崩潰執行
- 17. 我做了gps位置偵聽器,但我的位置更新需要權限?
- 18. 從Android設備獲得一致且及時的GPS位置?
- 19. 想要在android中以編程方式更改gps或位置服務設置?
- 20. 從iOS移植到Android - 我需要多少測試設備?
- 21. 在Android XML中將按鈕放在我想要的位置?
- 22. 想要通過我的應用禁用GPS設置
- 23. 在代碼中編譯,沒有得到我想要的行爲。
- 24. 流星Android設備上無法獲得GPS位置
- 25. 我想要的位置,但我得到ncols和陣列
- 26. 我不能從我的代碼得到想要的結果
- 27. 我需要爲移動設備製作多少個網站
- 28. 我需要通過代碼
- 29. 我想知道其他設備在我的iphone中的位置
- 30. file_get_contents需要php的內容!我需要在HTML代碼中的源代碼
我認爲好友,只要用第一行代碼就能讓你開始。在問任何問題之前,請做一些背景研究。由於您今天加入,如果您閱讀以下內容,將會對您有所幫助:http://stackoverflow.com/questions/how-to-ask –