1

I tried to get user location when user was movement. I wrote below code and i set smallest displacement to 30 meter and interval to 0 millisecond that i get location in every 30 meter movement but my application not worked correct. If i stop in a place, the application didn't get location and this is true but when i moved, sometimes i get location in 100 meter movement or more. Why? If i get location in more than 30 meter, i lost some points and this is important for me.

This is My Code for request location update:

 private void createLocationRequest() {
    mLocationRequest = new LocationRequest();
    mLocationRequest.setInterval(0);//(UPDATE_INTERVAL_IN_MILLISECONDS);
    mLocationRequest.setFastestInterval(0);//(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
    mLocationRequest.setSmallestDisplacement(30);
    mLocationRequest.setMaxWaitTime(MAX_WAITE_TIME);

    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}

2 Answers2

2

LocationRequest.setSmallestDisplacement doesn't give you a better accuracy, it's just to avoid unnecessary updates.

There is no method to enhance low accuracy, you just get a point with some accuracy, if you are not interested in positions with low accuracy just skip this location and wait for a better one.

No perfect accuracy is available now, the accuracy is 100m for worse accuracy.

check android developers page for more information:

https://developer.android.com/training/location/receive-location-updates#location-request

Try this: Set the accuracy level to ACCURACY_FINE

Set the highest power (to get best GPS signal)

Don’t request the altitude.

Set speedRequired to false

Set CostAllowed flag to true

Set BearingRequired to false

Set HorizontalAccuracy and VerticalAccuracy to HIGH

read more about these function, you will understand why.

Criteria tenM= new Criteria();
tenM.setAccuracy(Criteria.ACCURACY_FINE);
tenM.setPowerRequirement(Criteria.POWER_HIGH);
tenM.setAltitudeRequired(false);
tenM.setSpeedRequired(false);
tenM.setCostAllowed(true);
tenM.setBearingRequired(false);
tenM.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
tenM.setVerticalAccuracy(Criteria.ACCURACY_HIGH);

locationManager.requestLocationUpdates(1000 /*milliseconds*/,  1 
/*1 meter*/, 
tenM /*criteria*/, this /*context*/, null);
0xA
  • 1,519
  • 1
  • 9
  • 23
  • Thanks for your reply @KARAM JABER. Do you mean, i can't get location after 30 meter movement? and i just set displacement upper than 100 meter? I need update location after 30 meter in out door. – Fahimeh Hashemian Jan 20 '19 at 08:47
  • you can get the location after 30m but the problem its not perfect accuracy, so after setting your smallest displacement, the location request will fire only if you surpassed that displacement on the next update, if not it will not. now it will keep checking, if the new position is with low accuracy, you should skip that one and wait for the more accurate one, but by that time you would have moved more than 30m and you will be waiting for the next one. Even big companies such as whatsapp and facebook when sending location is only accurate to 20m-30m minimum. – 0xA Jan 20 '19 at 09:36
  • Thanks @KARAM JABER. If i don't skip that low accuracy location, what happened? and How works applications like waze? The waze get location periodically and show my location in every millisecond! – Fahimeh Hashemian Jan 20 '19 at 11:16
  • @FahimehHashemian you will get an undesired behavior, like what you are getting right now for 100m and not 30m. Check this edit for my answer, i got as accurate as 10m using. – 0xA Jan 20 '19 at 11:20
  • Finally @FahimehHashemian please setInterval not fastestInterval, setInterval is called faster than fastestInterval. The Irony – 0xA Jan 20 '19 at 11:28
  • Thanks, I red your answer but you use Location Manager. I want to use Fused Location Provider not Location Manager. and based on Android document, I set accuracy of my location with setPriority in locationRequest.. and i set interval and fast interval to 0 millisecond. – Fahimeh Hashemian Jan 21 '19 at 04:25
  • Can you send send a full method or class for getting location with 30 meter accuracy? because i can't understand what do i do! – Fahimeh Hashemian Jan 21 '19 at 04:32
0

That's because your location accuracy is above 30m (presumably much higher). So when you change your location by 100 m, you are still in the estimated location circle. You can get location accuracy to see if true, but anyway you don't have a better choice than get coordinates frequently and choose the one with most accuracy. See: FusedLocationProviderClient API LocationRequest setSmallestDisplacement doesn't work properly

Ali Has
  • 598
  • 1
  • 8
  • 24