request Location Update - Android Map

Android examples for Map:Location

Description

request Location Update

Demo Code


import java.util.Timer;
import java.util.TimerTask;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

public class Main{
    public static final String TAG = "CONGRESS";
    public static LocationTimer requestLocationUpdate(Context context,
            Handler handler, String provider) {
        Log.d(TAG,//  w  w w .ja  v a2s  .c o  m
                "LocationUtils - requestLocationUpdate(): from provider "
                        + provider);

        if (!(context instanceof LocationListener))
            throw new IllegalArgumentException(
                    "context must implement LocationListener to receive updates!");

        LocationListenerTimeout listener = (LocationListenerTimeout) context;
        LocationManager manager = (LocationManager) context
                .getSystemService(Context.LOCATION_SERVICE);

        LocationTimer timer = new LocationTimer(listener, manager,
                provider, handler);
        timer.start();
        return timer;
    }
}

Related Tutorials