日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[android] 手机卫士手机定位的原理

發(fā)布時間:2025/3/8 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [android] 手机卫士手机定位的原理 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

手機定位的三種方式:網(wǎng)絡(luò)定位,基站定位,GPS定位

?

?

網(wǎng)絡(luò)定位,手機連上wifi 2g 3g的時候,手機會有一個ip,誤差很大

基站定位,精確度與基站的多少有關(guān),幾十米到幾公里的誤差

GPS定位,至少需要三顆衛(wèi)星才能定位,在空曠的地方準確

?

手機使用A-GPS需要網(wǎng)絡(luò)來輔助定位,定位速度快,網(wǎng)絡(luò)記錄了上次的衛(wèi)星軌道,

?

?

獲取LocationManager對象,通過getSystemService(LOCATION_SERVICE)

調(diào)用LocationManager對象的requestLocationUpdates()方法,請求位置更新,參數(shù):

定位方式(“gps”),更新時間(60000),更新距離(50),LocationListener對象

?

LocationListener是一個接口,需要做它的實現(xiàn)類

定義MyLocationListener實現(xiàn)LocationListener,實現(xiàn)它下面的方法

onLocationChanged(),當位置改變的時候回調(diào),傳遞進來一個Location對象

調(diào)用location對象的getLongitude()方法,得到經(jīng)度

調(diào)用Location對象的getLatitude()方法,得到維度

調(diào)用Location對象的getAccuracy()方法,得到精確度

?

onStatusChanged(),當狀態(tài)改變的時候回調(diào),關(guān)閉 開啟

onProviderEnabled(),當某一個位置提供者可用了

onProviderDisabled(),當某一個位置提供者不可用了

?

activity銷毀的時候,取消監(jiān)聽位置

重寫activityonDestroy()方法

調(diào)用LocationManager對象的removeUpdates(),取消監(jiān)聽,參數(shù):LocationListener對象

LocationListener對象置為null,垃圾回收

?

需要的權(quán)限

android.permission.ACCESS_FINE_LOCATION 獲取精準位置

android.permission.ACCESS_COARSE_LOCATION 獲取粗略的位置

android.permission.ACCESS_MOCK_LOCATION 獲取模擬的位置(模擬器開發(fā)的時候)

?

模擬器上,ddms里面發(fā)送以下位置,才能顯示

?

國家對坐標進行了加偏處理,變成火星坐標,需要國家測繪局的插件,網(wǎng)上有火星坐標轉(zhuǎn)換代碼

package com.tsh.mylocation;import android.app.Activity; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast;public class MainActivity extends Activity {private LocationManager lm;private LocationListener listener;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);//獲取位置管理器lm=(LocationManager) getSystemService(LOCATION_SERVICE);listener=new MyLocationListener();lm.requestLocationUpdates("gps", 0, 0, listener);}private class MyLocationListener implements LocationListener{@Overridepublic void onLocationChanged(Location location) {//獲取經(jīng)度String longitude="經(jīng)度:"+location.getLongitude();String latitude="緯度:"+location.getLatitude();String acc="精確度:"+location.getAccuracy();Toast.makeText(MainActivity.this, longitude+latitude+acc, 1).show();}@Overridepublic void onStatusChanged(String provider, int status, Bundle extras) {}@Overridepublic void onProviderEnabled(String provider) {}@Overridepublic void onProviderDisabled(String provider) {}} }

?

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結(jié)

以上是生活随笔為你收集整理的[android] 手机卫士手机定位的原理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。