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

來源:互聯網
上載者:User

推薦閱讀:

淺析Android手機衛士sim卡綁定

深入淺析Android手機衛士儲存密碼時進行md5加密

詳解Android 手機衛士設定嚮導頁面

淺析Android手機衛士關閉自動更新

淺析Android手機衛士自訂控制項的屬性

淺析Android手機衛士讀取連絡人

淺析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手機衛士手機定位的原理,希望對大家有所協助!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.