onLocationChanged(Location location) is not working - Android [duplicate]

故事扮演 提交于 2019-12-08 15:05:25

问题


I have used manager.requestLocationUpdates("gps", 1800000, 1, new LocationDetector()); method of LocationManager manager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); class for getting update when either location change (device's location) is at least 1 meter (almost 40 inches), OR at least 30 minutes has passed. But the update is not being received when I change device's location by 1 meter (or even more). So what can be the problem? Please tell.

Code:

public class LocationDetector implements LocationListener {
    @Override
    public void onLocationChanged(Location location) {
        Log.d("GPS: ",location.getLatitude()+", "+location.getLongitude());
    }

回答1:


It's not OR, it's AND.

To get a location update with those parameters the distance needs to change at least 1 meter AND 30 minutes needs to have passed since the previous update.

Android documentation:

The minDistance parameter can also be used to control the frequency of location updates. If it is greater than 0 then the location provider will only send your application an update when the location has changed by at least minDistance meters, AND at least minTime milliseconds have passed.



来源:https://stackoverflow.com/questions/37095377/onlocationchangedlocation-location-is-not-working-android

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