国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

淺析Android手機衛士手機定位的原理

2020-02-21 17:28:54
字體:
來源:轉載
供稿:網友

現在是移動互聯網的時代,手機已經成為每個人生活的標準,應用程序安裝在各種手機上,提供各種服務,徹底改變了我們的生活,本文是武林技術頻道小編為大家提供的淺析Android手機衛士手機定位的原理,一起來看看吧!

手機定位的三種方式:網絡定位,基站定位,GPS定位

網絡定位,手機連上wifi 2g 3g的時候,手機會有一個ip,誤差很大

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

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

手機使用A-GPS需要網絡來輔助定位,定位速度快,網絡記錄了上次的衛星軌道,

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

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

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

LocationListener是一個接口,需要做它的實現類

定義MyLocationListener實現LocationListener,實現它下面的方法

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

調用location對象的getLongitude()方法,得到經度

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

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

onStatusChanged(),當狀態改變的時候回調,關閉 開啟

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

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

當activity銷毀的時候,取消監聽位置

重寫activity的onDestroy()方法

調用LocationManager對象的removeUpdates(),取消監聽,參數:LocationListener對象

把LocationListener對象置為null,垃圾回收

需要的權限

android.permission.ACCESS_FINE_LOCATION 獲取精準位置
android.permission.ACCESS_COARSE_LOCATION 獲取粗略的位置
android.permission.ACCESS_MOCK_LOCATION 獲取模擬的位置(模擬器開發的時候)

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

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

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) {//獲取經度String longitude="經度:"+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) {}}}

淺析Android手機衛士手機定位的原理就給大家介紹到這里了,相信網友們看了上面的介紹之后已經有所了解了,希望能夠幫助在程序世界拼搏的你。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 通道| 晋江市| 龙州县| 林周县| 屯门区| 岑巩县| 丹东市| 浠水县| 射洪县| 黑水县| 搜索| 宣恩县| 清水县| 芦山县| 信丰县| 莆田市| 轮台县| 蓬莱市| 镇坪县| 利津县| 蓝田县| 巴林右旗| 彩票| 梨树县| 华安县| 婺源县| 凌海市| 嘉黎县| 漳平市| 叶城县| 巴塘县| 甘南县| 环江| 嘉鱼县| 余庆县| 茂名市| 辽源市| 岚皋县| 五大连池市| 阿尔山市| 湛江市|