什么是使用LocationClient定期获得更新的最电池有效的方法?电池、有效、方法、LocationClient

2023-09-06 02:41:53 作者:死亡的 寂静

我想有两个独立的报警器每隔一小时,一个熄灭每次59分钟连接客户端,第二真正得到的位置,并且随后切断客户端收集用户的位置数据。

在电池续航方面,有什么事我应该考虑如果获取用户的位置将是应用程序的主要排水干什么?或者,是否有不同的方法有两个报警?我原本只是有一个单一的报警器,但执行(!mLocationClient.isConnected)然后连接检查不给客户足够的时间来进行连接。

感谢您的见解。

这两个报警器会响的东西是这样的:

 私人INT PERIODIC_UPDATE = 60000 * 60; //获取位置和断开每隔一小时
私人诠释PERIODIC_RECONNECTION_UPDATE = 60000 * 59; //的getLocation呼叫之前连接1分钟

    定时器toReconnect =新的Timer();
    toReconnect.schedule(新的TimerTask(){

        @覆盖
        公共无效的run(){
            mLocationClient.connect();
        }
    },5000,PERIODIC_RECONNECTION_UPDATE);

    定时器theTimer =新的Timer();
    theTimer.schedule(新的TimerTask(){
        @覆盖
        公共无效的run(){
            尝试 {
                如果(!mLocationClient.isConnected()){
                    mLocationClient.connect();
                    //这不会有太大的影响,因为不可能那么快,将删除。
                }

                位置theLocation = mLocationClient.getLastLocation();
                如果(theLocation!= NULL){
                    checkPostLocation(theLocation);

                    mLocationClient.disconnect();
                }
            }赶上(例外五){
                e.printStackTrace();
            }
        }},5000,PERIODIC_UPDATE);
 

解决方案

你真的需要跟踪用户?

强烈推荐3款Win和Mac可以用的神奇软件,都是神器

如果它只是用户界面,然后用getLastKnownLocation(PASSIVE_PROVIDER),你应该得到的东西半准确的假设他们使用位置服务在手机上的其他地方。

如果您需要实际三角用户,实现了不同的供应商使用不同的电池。被动<网络12;全球定位系统。

您找到用户,更多的电池,GPS以最电池的时间越多。

首先,意图一个时间表,1小时或什么的,必要的,只有一个服务的服务。只能活最多一分钟(或更少)的,听上的所有位置提供者。过了一分钟,或精度不够好,你保存结果并关闭该服务。

I am thinking about having two separate alarms to gather a user's location data every hour, one that goes off every 59 minutes to "connect" the client and a second to actually get the location and then subsequently disconnect the client.

In terms of battery life, is there anything else I should consider doing if getting the user's location will be the primary drain of the app? Or, is there a different approach to having two alarms? I originally only had a single alarm, but performing a (!mLocationClient.isConnected) then connect check does not give the client enough time to connect.

Thanks for your insight.

The two alarms would go off something like this:

private int PERIODIC_UPDATE = 60000*60;  //gets location and disconnects every hour
private int PERIODIC_RECONNECTION_UPDATE = 60000*59;  //connects 1 minute before getLocation call

    Timer toReconnect = new Timer();
    toReconnect.schedule(new TimerTask() {

        @Override
        public void run() {
            mLocationClient.connect();
        }
    }, 5000, PERIODIC_RECONNECTION_UPDATE);

    Timer theTimer = new Timer(); 
    theTimer.schedule(new TimerTask(){
        @Override
        public void run() {
            try {
                if(!mLocationClient.isConnected()) {
                    mLocationClient.connect();
                    //This will not have much affect because cannot so quickly, will remove. 
                }

                Location theLocation = mLocationClient.getLastLocation();
                if(theLocation!=null) {
                    checkPostLocation(theLocation); 

                    mLocationClient.disconnect();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }   
        }}, 5000, PERIODIC_UPDATE);

解决方案

Do you actually need to track the user?

If it's just about UI, then use getLastKnownLocation(PASSIVE_PROVIDER) and you should get something semi-accurate assuming they used location services on their phone somewhere else.

If you need to actually triangulate the user, realize the different providers use different battery. Passive < Network < GPS.

The more you locate the user, the more battery with GPS taking the most battery and time.

Start the service by intent one a schedule, 1 hour or whatever, only one service necessary. Only live for a maximum of 1 minute (or less), listen on all Location providers. After the minute or accuracy is good enough, you save the result and shut down the service.