相关疑难解决方法(0)

Android:电子邮件使用率低的Google地图位置

我的应用目前正在使用Google地图 Google Play Services

speficying:

mMap.setMyLocationEnabled(true);

每当我在我的应用程序中显示地图时,我都会意识到:

  • 该位置在地图上以蓝点表示
  • 顶部栏中显示位置图标
  • 如果我进入手机的设置/位置,我的应用报告为"高电量使用"

但是,我可以看到有些应用程序使用地图并仍然显示位置蓝点,但位置图标不会出现在顶部栏中,并且它们的电池使用率很低.

我的应用目前授予两种权限:

  • android.permission.ACCESS_COARSE_LOCATION
  • android.permission.ACCESS_FINE_LOCATION

我的问题是:

如何在电池使用率低的情况下显示蓝点位置?

是否可以通过代码指定准确度/电池使用情况?

UPDATE

实际上我意识到这样做的方法是使用GoogleApiClient'sFusedLocationApi

    mGoogleApiClient = new GoogleApiClient.Builder(context)
            .addApi(LocationServices.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
Run Code Online (Sandbox Code Playgroud)

我在我的Activity中配置了GoogleApiClient,调用:

  • GoogleApiClient.connect() 在活动的开始
  • GoogleApiClient.disconnect() 在活动的停止

onConnected回调中,我设置了位置更新的标准:1分钟的最快间隔,具有低功率优先级:

    private static final LocationRequest REQUEST = LocationRequest.create()
        .setFastestInterval(60000)   // in milliseconds
        .setInterval(180000)         // in milliseconds
        .setPriority(LocationRequest.PRIORITY_LOW_POWER);

    @Override
    public void onConnected(Bundle bundle) {
        LocationServices.FusedLocationApi.requestLocationUpdates(
            mGoogleApiClient,
            REQUEST,
            this);  // LocationListener
    }
Run Code Online (Sandbox Code Playgroud)

我已经测试了GoogleApiClient在开始时正确连接,但出于某些原因,每当我使用嵌入式MapView访问片段时,我仍然可以在设置/位置屏幕上为我的应用程序获得高电量!

似乎MapView忽略了这些低功耗标准!

android google-maps google-play-services google-maps-android-api-2 location-services

11
推荐指数
2
解决办法
2万
查看次数