Google Play服务位置api有时会给出错误的位置 [英] google play services location api sometimes give wrong location

查看:174
本文介绍了Google Play服务位置api有时会给出错误的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用使用Google Play服务API来获取用户位置,并检查设备是在半径50 mt的特定区域之内还是之外。
该应用使用PRIORITY_HIGH_ACCURACY,间隔为1分钟。
因此,我创建了GoogleApiClient:

My app use Google Play service API to get the user location and check if the device is inside or outside a particular area of 50 mt of radius. The app use PRIORITY_HIGH_ACCURACY and a Interval of 1 minute. So I create GoogleApiClient:

mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();
    mGoogleApiClient.connect();

在onConnected回调中:

In the onConnected callback:

    mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(60000);
    mLocationRequest.setFastestInterval(10000);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

MyLocationListener.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, mLocationListener);

我的应用还根据精度(如果精度> 200 mt,我将其丢弃)和时间(如果它太旧了,我将其丢弃。)

My app also filter locations based on accuracy (if accuracy > 200 mt I discard it) and time (if it is too old I discard it).

该应用程序可以正常运行,但在某些特定区域(有时它返回错误的位置)距实际位置约500米,并且那些错误的位置总是在同一地方,离蜂窝塔有些距离。

The app works fine except in some particular areas where sometimes it returns wrong locations update about 500 meters from the real location, and those wrong locations are always near the same place, some step away from a Cell Tower.

在那些区域,我得到了错误和正确位置的组合,而我的应用程序认为该设备有时在关注区域内,有时在关注区域外。

In those areas I get a combination of wrong and correct locations and my app think that the device is sometimes inside and sometimes outside the area of interest.

当我收到位置更新信息时,我会连续等待其他3个信息来确认位置。另外,如果与之前的位置完全相同,我也会过滤位置。这意味着当我遇到这些错误时,我会连续收到4个错误的位置,每个位置与其他位置略有不同。

When I get a location update I wait for other 3 in a row to confirm the position. Also I filter location if exactly the same as the previous. This means that when I m getting those errors I'm receiving 4 wrong locations in a row each one slightly different from the others.

有没有办法防止这种行为?

Is there a way to prevent this behavior? Can this be caused by the Cell Tower?

推荐答案

更改 setInterval(60000) setInterval(20000) 5000

由于间隔为一分钟,因此即使用户移动也不会获得更新。这就是为什么存在误差的原因。

Since the interval is one minute, you won't get updates even if the user moves. That's why there is an inaccuracy.

根据Google的说法, setInterval(long)的意思是-设置要获取位置的时间间隔。 setFastestInterval(long)意思是-如果可以尽快找到一个位置(例如,另一个应用程序正在使用位置服务。也就是说,如果没有其他应用程序正在使用位置服务,那么一分钟后您将获得更新)。

According to Google, setInterval(long) means - set the interval in which you want to get locations. setFastestInterval(long) means - if a location is available sooner you can get it (i.e. another app is using the location services. Means, if no other apps are using the location service, you will get updates only after a minute).

这篇关于Google Play服务位置api有时会给出错误的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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