Android的GPS精度甚至还没有接近内置的地图应用程序 [英] Android GPS accuracy not even close to built in maps app

查看:197
本文介绍了Android的GPS精度甚至还没有接近内置的地图应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Android SDK中经历过了,现在几个星期,试图实现从后台服务的准确位置。

I've been experimenting with the Android SDK for a few weeks now, trying to achieve an accurate location from a background service.

尝试一些配置后,我现在有这样一个循环:

After trying a few configurations, I currently have this on a loop:

Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(true);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_HIGH);
bestProvider = locationManager.getBestProvider(criteria, true);
lastKnownLocation = locationManager.getLastKnownLocation(bestProvider);

然后我检查 lastKnownLocation 飘飞的位置更新。我知道你可以听进行更新,但此刻的我不是太在意,现在这种权利。我所关心的是,(我认为)我所要求的手机使用GPS尽可能 - 而不是确定位置的其他方法 - 一但它仍然会返回从好距离纬度/经度而去,但是当我打开地图应用程序,它有我一对夫妇的米范围内。

And then I check lastKnownLocation every now and then for a position update. I know you can listen for updates but at the moment I'm not too concerned about that right now. What I am concerned about is, (I think) I'm asking for the phone to use GPS whenever possible - instead of other methods of determining the location - an yet it still returns a latitude / longitude from a good distance away, yet when I open the maps application, it has me within a couple of meters.

任何人都可以提出我要去哪里错在这里?

Can anyone suggest where I'm going wrong here?

推荐答案

设置标准刚刚确立了其供应商最好是根据他们使用,这样并没有真正对准确性或位置的有效性有发言权。我刚才设置的提供商马上GPS(全球定位系统如果可以!)。

Setting the Criteria just establishes which provider is best to use depending on them so that doesn't really have a say on the accuracy or the validity of the location. I just set the provider to GPS straight away (If GPS is available!).

此外,它似乎并不像你给它有关多久你想基于时间和距离更新前等待的任何要求。这里是什么我使用意图和广播接收器的一个例子。它可以帮助你。

Also it doesn't seem like your giving it any requirements concerning how long you want to wait before updating based on time and distance. Here is an example of what I do using intents and broadcast receiver. It may help you.

public void beginMonitoringLocation(int minDistance) {
            IntentFilter filter = new IntentFilter();
            filter.addAction(MainActivity.LOCATION_UPDATE_ACTION);
            this.mContext.registerReceiver(this.locationReceiver, filter);

            LocationManager mLocationManager = (LocationManager) this.mContext.getSystemService(Context.LOCATION_SERVICE);
            mLocationManager.addGpsStatusListener(this);
            boolean enabled =  mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

            if (!enabled) {
                Log.e("LocationManager", "GPS not enabled!!!!");
            } 

            LocationProvider provider = mLocationManager.getProvider(LocationManager.GPS_PROVIDER); // GET THE BEST PROVIDER FOR OUR LOCATION
            Log.d("LocationManager:","Location Provider:"+provider);
            if ( provider == null ) {
                Log.e( "LocationManager", "No location provider found!" );
                return;
            }

            final int locationUpdateRC=0;

            int flags = 0;

            Intent intent = new Intent(MainActivity.LOCATION_UPDATE_ACTION); 
            PendingIntent pendingIntent = PendingIntent.getBroadcast(this.mContext, locationUpdateRC, intent, flags); 
            // PENDING INTENT TO BE FIRED WHEN THE LOCATIONMANAGER RECEIVES LOCATION UPDATE.
            // THIS PENDING INTENT IS CAUGHT BY OUR BROADCAST RECEIVER
            mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,minDistance,pendingIntent);
            this._monitoringLocation = true;
    }

然后在同一个班,我把我的广播接收器

public BroadcastReceiver locationReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
            Location location = (Location) intent.getExtras().get(LocationManager.KEY_LOCATION_CHANGED);
        if (location != null) {
            //Do something with it  
        }
        }
    };

我的意图过滤器的作用只是一个静态的参考我的活动设定的常数。

The action for my intent filter is just a static reference to a constant set in my activity.

public static final String LOCATION_UPDATE_ACTION = "com.corecoders.sqlmaptrack.LOCATION_UPDATE_RECEIVED";

这曾在我的情况下,为我提供准确的位置。您可以将距离设置为0,如果你想要什么,然后你就会发现你获得的5每一秒的精度的位置修正,如果你有4颗卫星以上的良好的修复。

This worked in my case in providing me with accurate locations. You can set the distance to 0 if you want then what you will find is you get location fixes of an accuracy of 5 every second if you have a good fix of 4 satellites or more.

我希望这可以帮助你。

这篇关于Android的GPS精度甚至还没有接近内置的地图应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆