开发者

Android how to use GPS lastknownlocation IFF locationchangedlistener won't run

I have a service that runs this thread to get GPS coordinates

   LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
   GpsListener gpsLocationListener = new GpsListener();
   long minTime = 5000; // 5 sec for test purposes...
   float minDistance = 1;
   lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime,
            minDistance, gpsLocationListener);

and of course my gpsLocationListener looks like this:

   class GpsListener implements LocationListener{

        public void onLocationChanged(Location location) {
              // TODO Auto-generated method stub
              latitude = location.getLatitude();
              longitude = location.getLongitude();
              //float speed = location.getSpeed();
              checkin();

        }

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

        }

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

        }


        @Override
        public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
            // TODO Auto-generated method stub

        }

}

where the onLocationChanged method sends the latitude and longitude to a server once it is obtained.

Unfortunately this method doesn't run as reliabl开发者_StackOverflow社区y as I'd like in my testing, where I basically get up and walk around to see if it registers my location has changed.

How do I make a different function run if it hasn't updated in X amount of seconds. This different function will simply send the last known coordinates?

Insight appreciated!


You would need to set up a recurring timer. Android - Reliably getting the current location might help you in what you are trying to do.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜