首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >android中基于位置服务的应用程序

android中基于位置服务的应用程序
EN

Stack Overflow用户
提问于 2016-07-29 03:01:12
回答 1查看 70关注 0票数 0

我已经开发了一个android应用程序,它可以检查位置更新,并在一定时间后将位置数据发送到服务器。我测试了两种方法;一种是使用Google location apI,另一种是使用Android服务。但这两款应用都太耗电了。我需要优化电池的使用,这样用户就可以根据需要使用应用程序。

有几个应用程序可以一直跟踪我们的位置,而且不会妨碍电池;例如endomondo,Facebook等。我特别想提到endomondo,因为它在工作时真的工作得很好。

有没有人能给我提个建议,让android应用实现位置感知的最好方法?

如何让我的应用程序像endomondo或类似的位置感知应用程序?

请建议我做这件事的更好方法。

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2016-07-29 07:29:32

你有没有尝试过通过检查LocationManagar是否有足够好的位置来减少GPS位置跟踪?(也许是其他应用程序跟踪?)

例如:

代码语言:javascript
运行
复制
    private static Location bestLastKnownLocation(float minAccuracy, long maxAge, LocationManager mLocationManager) {

    Location bestResult = null;
    float bestAccuracy = Float.MAX_VALUE;
    long bestAge = Long.MIN_VALUE;

    List<String> matchingProviders = mLocationManager.getAllProviders();

    for (String provider : matchingProviders) {

        Location location = mLocationManager.getLastKnownLocation(provider);

        if (location != null) {

            float accuracy = location.getAccuracy();
            long time = location.getTime();

            if (accuracy < bestAccuracy) {

                bestResult = location;
                bestAccuracy = accuracy;
                bestAge = time;

            }
        }
    }

    // Return best reading or null
    if (bestAccuracy > minAccuracy  || (System.currentTimeMillis() - bestAge) > maxAge) {
        return null;
    } else {
        return bestResult;
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38644699

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档