资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Android源码个个击破之LocationManager-创新互联

GPS NMEA-0183标准数据介绍

创新互联是一家专注于成都网站设计、成都网站建设与策划设计,宣威网站建设哪家好?创新互联做网站,专注于网站建设十余年,网设计领域的专业建站公司;建站业务涵盖:宣威等地区。宣威做网站价格咨询:18980820575

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

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


新闻名称:Android源码个个击破之LocationManager-创新互联
链接分享:http://cdkjz.cn/article/dhggce.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220