网站建设资讯

NEWS

网站建设资讯

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
URL地址:http://cdweb.net/article/igihhs.html