开发者

How to fetch the current Location in every 1 min of interval?

I have implemented the Demo to show the current lat-long of the User. Now I am able to see the lat-long of the current Position. but I want to Set it to to be displayed in every 1 min of interval. The code is as below:

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        LocationListener lListener = new mylocationlistener();
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, lListener);
    }

    private class mylocationlistener implements LocationListener {
        @Override
        public void onLocationChanged(Location location) {
            if (location != null) {
            Log.d("开发者_如何学PythonLOCATION CHANGED", location.getLatitude() + "");
            Log.d("LOCATION CHANGED", location.getLongitude() + "");
            Toast.makeText(MainActivity.this,
                "My current location:\nLatitude:"+location.getLatitude() + "\nLogitude:" + location.getLongitude(),Toast.LENGTH_LONG).show();
            }
        }

        @Override
        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            // TODO Auto-generated method stub

        }
    }
}

So, What should I have to do to make it to display the current lat-long in every 1 min of interval? I think I have to use the thread to implement it. How to make it possible?


lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, lListener);

The argument in the method signify - provider, time, distance and the location listener.

Therefore to request an update from the Location listener you need to set the second parameter to 1000*60, because the time is recorded in milliseconds.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜