google play services location api sometimes give wrong location

柔情痞子 提交于 2019-12-12 03:25:35

问题


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();

In the onConnected callback:

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

and

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

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).

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.

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?


回答1:


There's always a chance of it being wrong. An accuracy of 200m doesn't mean its within 200m- it means there's a 67% chance you're within 200m. There's still a 1/3 chance you aren't.

Since most of the Google Play location providers are fused (use GPS and wifi/cell data), yes being very close to a tower could screw with the data.




回答2:


Change setInterval(60000) to setInterval(20000) or to 5000.

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

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).



来源:https://stackoverflow.com/questions/35095177/google-play-services-location-api-sometimes-give-wrong-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!