溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Android源碼個個擊破之LocationManager

發布時間:2020-07-04 19:38:15 來源:網絡 閱讀:5804 作者:屠夫章哥 欄目:移動開發

?GPS NMEA-0183標準數據介紹

https://www.cnblogs.com/rechen/p/5135409.html? (可以準確判斷是否在定位)









源碼分析:

? ??https://www.ibm.com/developerworks/cn/opensource/os-cn-android-location/

????

?1.?源碼所在的目錄

2.?

http://ju.outofmemory.cn/entry/111182

3.?

4.?LocationManager生成實例的位置

5.?frameworks/base/core/java/android/app/ContextImpl.java


registerService(LOCATION_SERVICE,?new?ServiceFetcher()?{
????public?Object?createService(ContextImpl?ctx)?{
????????IBinder?b?=?ServiceManager.getService(LOCATION_SERVICE);
????????return?new?LocationManager(ctx,?ILocationManager.Stub.asInterface(b));
????}
});

???????而ServiceManager里的的"LOCATION_SERVICE"又是從com.android.server.SystemServer這個類添加進去的

if?(!disableLocation)?{
????traceBeginAndSlog("StartLocationManagerService");
????try?{
????????location?=?new?LocationManagerService(context);
????????ServiceManager.addService(Context.LOCATION_SERVICE,?location);
????}?catch?(Throwable?e)?{
????????reportWtf("starting?Location?Manager",?e);
????}
????Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);

????traceBeginAndSlog("StartCountryDetectorService");
????try?{
????????countryDetector?=?new?CountryDetectorService(context);
????????ServiceManager.addService(Context.COUNTRY_DETECTOR,?countryDetector);
????}?catch?(Throwable?e)?{
????????reportWtf("starting?Country?Detector",?e);
????}
????Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
}

? ?LocationManagerService的reportLocation方法觸發了應用上層onLocationFound的回調

@Override
public?void?reportLocation(Location?location,?boolean?passive)?{
????checkCallerIsProvider();

????if?(!location.isComplete())?{
????????Log.w(TAG,?"Dropping?incomplete?location:?"?+?location);
????????return;
????}

????mLocationHandler.removeMessages(MSG_LOCATION_CHANGED,?location);
????Message?m?=?Message.obtain(mLocationHandler,?MSG_LOCATION_CHANGED,?location);
????m.arg1?=?(passive???1?:?0);
????mLocationHandler.sendMessageAtFrontOfQueue(m);
}

????順藤摸瓜,最終找到

public?boolean?callLocationChangedLocked(Location?location)?{
????if?(mListener?!=?null)?{
????????try?{
????????????synchronized?(this)?{
????????????????//?synchronize?to?ensure?incrementPendingBroadcastsLocked()
????????????????//?is?called?before?decrementPendingBroadcasts()
????????????????mListener.onLocationChanged(new?Location(location));
????????????????//?call?this?after?broadcasting?so?we?do?not?increment
????????????????//?if?we?throw?an?exeption.
????????????????incrementPendingBroadcastsLocked();
????????????}
????????}?catch?(RemoteException?e)?{
????????????return?false;
????????}
????}?else?{

????那么LocationManagerService的reportLocation方法又是怎么被觸發的呢?

? ??

?

????

1.?ILocationManager.aidl

2.?frameworks/base/location/java/android/location/ILocationManager.aidl

3.?

4.?

? GPS定位漂移產生的原因:https://baike.1688.com/doc/view-d41865087.html

? GPS的NEMA協議解析:https://blog.csdn.net/adazone/article/details/45152291

? 點到直線的距離計算公式:https://blog.csdn.net/bagboy_taobao_com/article/details/6291462

? 經緯度求坐標方位角:?https://blog.csdn.net/u010175314/article/details/76093934

? NMEA編碼:https://baike.baidu.com/item/NMEA/9812575?fr=aladdin


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女