Android源码个个击破之LocationManager

 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


文章标题:Android源码个个击破之LocationManager
文章起源:http://bzwzjz.com/article/igihhs.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 企业手机网站建设 重庆电商网站建设 企业网站设计 成都h5网站建设 定制网站设计 成都网站建设 企业网站设计 企业网站建设 外贸网站设计方案 成都商城网站建设 移动网站建设 阿坝网站设计 网站设计公司 H5网站制作 营销网站建设 成都网站建设 成都响应式网站建设 成都企业网站建设 成都网站建设 定制级高端网站建设 成都响应式网站建设公司 成都网站建设