ACCESS_COARSE_LOCATION许可给出的Andr​​oid手机发射塔precision [英] ACCESS_COARSE_LOCATION permission gives a cell tower precision on Android

查看:436
本文介绍了ACCESS_COARSE_LOCATION许可给出的Andr​​oid手机发射塔precision的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与 requestLocationUpdates一些测试() FusedLocationApi 功能。我现在用的<一个href="https://developer.android.com/reference/com/google/android/gms/location/LocationRequest.html#PRIORITY_BALANCED_POWER_ACCURACY">PRIORITY_BALANCED_POWER_ACCURACY.一个街区precision是为我好。

I am making some tests with the requestLocationUpdates() function from the FusedLocationApi. I am using the PRIORITY_BALANCED_POWER_ACCURACY. A city block precision is fine for me.

当我请求<一href="http://developer.android.com/reference/android/Manifest.permission.html#ACCESS_FINE_LOCATION">ACCESS_FINE_LOCATION允许,我避开100米precision这是伟大的 GPS 关闭。由于我并不需要一个GPS precision而是一个街区precision,我想请求仅 ACCESS_COARSE_LOCATION 许可。然而,当我要求 ACCESS_COARSE_LOCATION 许可,我得到2公里的precision。看来,该设备已经不使用无线的权限,只有手机信号塔precision。

When I request the ACCESS_FINE_LOCATION permission, I get around a 100m precision which is great with GPS off. As I do not need a GPS precision but a city block precision, I would like to request only the ACCESS_COARSE_LOCATION permission. However when I request the ACCESS_COARSE_LOCATION permission, I get a 2 km precision. It seems that the device does not use anymore the Wifi permission and only a cell tower precision.

我怎样才能有更好的precision与<一个href="http://developer.android.com/reference/android/Manifest.permission.html#ACCESS_COARSE_LOCATION">ACCESS_COARSE_LOCATION许可?

How can I have a better precision with the ACCESS_COARSE_LOCATION permission?

注:该 GPS 禁用我的测试设备上。

Note: the GPS is disabled on my test device.

推荐答案

这是一个有趣的问题,我是在IM pression,使用 ACCESS_COARSE_LOCATION 会使用无线网络,因为这是什么文件说。

This is an interesting problem, and I was under the impression that using ACCESS_COARSE_LOCATION would use WiFi, since that's what the documentation says.

的文档 ACCESS_COARSE_LOCATION 规定:

允许一个应用程序来访问网络衍生的大致位置   位置源,例如手机信号塔和Wi-Fi。

Allows an app to access approximate location derived from network location sources such as cell towers and Wi-Fi.

于是,我把它放到测试,其结果是令人惊讶的。

So, I put it to the test, and the results are surprising.

下面是code,我用于测试:

Here is the code that I used to test with:

public class MainActivity extends Activity implements
        GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener {

    LocationRequest mLocationRequest;
    GoogleApiClient mGoogleApiClient;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        buildGoogleApiClient();
        mGoogleApiClient.connect();
    }

    @Override
    protected void onPause(){
        super.onPause();
        if (mGoogleApiClient != null) {
            LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
        }
    }

    protected synchronized void buildGoogleApiClient() {
        Toast.makeText(this,"buildGoogleApiClient",Toast.LENGTH_SHORT).show();
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(LocationServices.API)
                .build();
    }

    @Override
    public void onConnected(Bundle bundle) {
        Toast.makeText(this,"onConnected",Toast.LENGTH_SHORT).show();

        mLocationRequest = new LocationRequest();
        mLocationRequest.setInterval(10);
        mLocationRequest.setFastestInterval(10);
        mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
        //mLocationRequest.setPriority(LocationRequest.PRIORITY_LOW_POWER);
        //mLocationRequest.setSmallestDisplacement(0.1F);

        LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
    }

    @Override
    public void onConnectionSuspended(int i) {
        Toast.makeText(this,"onConnectionSuspended",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {
        Toast.makeText(this,"onConnectionFailed",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onLocationChanged(Location location) {

        Log.d("locationtesting", "accuracy: " + location.getAccuracy() + " lat: " + location.getLatitude() + " lon: " + location.getLongitude());

        Toast.makeText(this,"Location Changed",Toast.LENGTH_SHORT).show();
    }
}

AndroidManifest.xml中:

AndroidManifest.xml:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

build.gradle:

build.gradle:

compile 'com.google.android.gms:play-services:7.3.0'

第一次测试,我做的是与 PRIORITY_BALANCED_POWER_ACCURACY ,也没有WiFi功能。请注意,我也被禁用总是允许扫描,因为它规定:

The first test I did was with PRIORITY_BALANCED_POWER_ACCURACY, and no WiFi. Note that I also disabled Always Allow Scanning, since it states:

让谷歌位置服务和其他应用程序扫描无线网络连接   网络,即使在无线网络连接关闭

Let Google Location Service and other applications scan for Wi-Fi networks, even when Wi-Fi is off

所以,这肯定会影响结果,如果它被启用。

So, that would certainly skew the results if it was enabled.

请注意,我也有在电池节能模式定位模式设置为所有测试,因此GPS无线电被关的全部时间。

Note that I also had Location Mode set in Battery Saving Mode for all tests, so the GPS radio was off the entire time.

下面是 PRIORITY_BALANCED_POWER_ACCURACY ACCESS_COARSE_LOCATION 的结果,并没有WiFi:

Here are the results of PRIORITY_BALANCED_POWER_ACCURACY, ACCESS_COARSE_LOCATION, and no WiFi:

accuracy: 2000.0 lat: 37.78378378378378 lon: -122.40320943772021

所以,它说2000米准确性,这里的实际坐标有多远,绿色箭头表示,我其实是:

So, it says 2000 meter accuracy, and here is how far away the actual coordinates are, the green arrow shows where I actually am:

然后,我启用了无线网络,并再次运行测试,并且出人意料的是,结果是完全一样的!

Then, I enabled WiFi, and ran the test again, and surprisingly, the results were exactly the same!

accuracy: 2000.0 lat: 37.78378378378378 lon: -122.40320943772021

然后,我在 LocationRequest 切换到 LocationRequest.PRIORITY_LOW_POWER 同时保持机器人。 permission.ACCESS_COARSE_LOCATION 在AndroidManifest.xml。

Then, I switched to LocationRequest.PRIORITY_LOW_POWER in the LocationRequest while keeping android.permission.ACCESS_COARSE_LOCATION in the AndroidManifest.xml.

无WiFi:

accuracy: 2000.0 lat: 37.78378378378378 lon: -122.40320943772021

使用的WiFi:

accuracy: 2000.0 lat: 37.78378378378378 lon: -122.40320943772021

结果都是一模一样又一样! 使用 PRIORITY_LOW_POWER 有同样的效果与使用 PRIORITY_BALANCED_POWER_ACCURACY ,在WiFi的状态似乎并没有对精度有任何影响的坐标。

The results were exactly the same again! Using PRIORITY_LOW_POWER had the same results as using PRIORITY_BALANCED_POWER_ACCURACY, in that the WiFi state did not seem to have any effect on accuracy of coordinates.

然后,就到涵盖所有的基础,我改回 LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY ,并切换到的Andr​​oidManifest.xml ACCESS_FINE_LOCATION

Then, just to cover all the bases, I changed back to LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY, and switched the AndroidManifest.xml to ACCESS_FINE_LOCATION :

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

第一次测试,没有WiFi:

First test, no WiFi:

accuracy: 826.0 lat: 37.7825458 lon: -122.3948752

所以,它说826米的精度,并在这里是多么接近上图:

So, it says accuracy of 826 meters, and here is how close it was on the map:

然后,我开机的WiFi,这里是结果:

Then, I powered on WiFi, and here is the result:

accuracy: 18.847 lat: 37.779679 lon: -122.3930918

它的字面发现的,因为你可以在地图上看到:

It's literally spot on, as you can see on the map:

看来你在你的 LocationRequest 在Java code使用你在AndroidManifest.xml中使用的权限,因为它的问题更小,此处的结果清楚地表明,当使用 ACCESS_FINE_LOCATION ,系统具有从WiFi无线电或关闭制成的准确性的巨大差异,而且它也是在一般更准确

It seems that it matters less what you use in your LocationRequest in the Java code, and more what permission you use in the AndroidManifest.xml, since the results here clearly show that when using ACCESS_FINE_LOCATION, having the WiFi radio on or off made a huge difference in the accuracy, and it was also more accurate in general.

这当然好像该文档是有点怀念领先,而且在使用 android.permission.ACCESS_COARSE_LOCATION ,其在无线电台或关闭不有所作为,当你的应用程序是唯一一个让位置请求。

It certainly seems as though the documentation is a bit miss-leading, and that while using android.permission.ACCESS_COARSE_LOCATION, having the WiFi radio on or off doesn't make a difference when your app is the only one making location requests.

另一件事是,文档指出的是,使用 PRIORITY_BALANCED_POWER_ACCURACY 将让你的背驮式应用到其他应用程序做位置请求。 从文档:

Another thing that the documentation states is that using PRIORITY_BALANCED_POWER_ACCURACY will let your app "piggy-back" onto location requests made by other apps. From the documentation:

他们只被分配动力归结为区间由设置   的setInterval(长),但是仍然可以接收其他触发的位置   应用的速度高达setFastestInterval(长)。

They will only be assigned power blame for the interval set by setInterval(long), but can still receive locations triggered by other applications at a rate up to setFastestInterval(long).

,如果用户打开了谷歌地图所以,根据文档你的应用可以获取在该点的更准确位置。这是使用新的融合位置提供者,而不是旧的API的主要上行侧之一,因为它降低了您的应用程序的电池漏电量,而不需要您大量的工作。

So if the user opens up Google Maps, according to the documentation your app can obtain a more accurate location at that point. That is one of the major up-sides of using the new Fused Location Provider rather than the older APIs, since it decreases the amount of battery drain of your app without much work on your part.

编辑:我执行此功能的测试,看看在使用会发生什么 ACCESS_COARSE_LOCATION

I performed a test of this functionality, to see what would happen while using ACCESS_COARSE_LOCATION.

第一个测试: ACCESS_COARSE_LOCATION PRIORITY_BALANCED_POWER_ACCURACY ,和WiFi的:

First Test: ACCESS_COARSE_LOCATION, PRIORITY_BALANCED_POWER_ACCURACY, and WiFi on:

accuracy: 2000.0 lat: 37.78378378378378 lon: -122.38041129850662

这是把我在水里,很远从我的当前位置。 然后,我退出了测试程序,推出了谷歌地图,它位于我到底我在哪里,然后重新启动测试程序。 测试程序无法背驮式上,从谷歌地图的位置,结果是完全和以前一样!

That placed me out in the water, quite far from my current location. Then, I exited the test app, launched Google Maps, which located me exactly where I am, then re-launched the test app. The test app was not able to piggy-back onto the location from Google Maps, and the result was exactly the same as before!

accuracy: 2000.0 lat: 37.78378378378378 lon: -122.38041129850662

我重新测试了几次,只是可以肯定的,但它确实看起来像使用 ACCESS_COARSE_LOCATION 还禁用应用程序的能力背驮式的通过其他应用程序获得的位置。

I re-tested this a few times, just to be sure, but it really looks like using ACCESS_COARSE_LOCATION also disables the ability of apps to "piggy-back" on to locations obtained by other apps.

它看起来像使用 ACCESS_COARSE_LOCATION 在AndroidManifest.xml真正削弱在获得precise位置数据方面的应用。

It looks like using ACCESS_COARSE_LOCATION in the AndroidManifest.xml really cripples the app in terms of getting precise location data.

在最后,你真的可以做的唯一事情是磨练的设置,为您和您的应用程序工作,本次测试的有希望的结果,可以帮助你做出这个决定的最佳组合。

In conclusion, the only thing you can really do is hone in on the best combination of settings that work for you and your app, and hopefully the results of this test can help you make that decision.

这篇关于ACCESS_COARSE_LOCATION许可给出的Andr​​oid手机发射塔precision的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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