Java tutorial
//package com.java2s; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; public class Main { private static final int RUN_ONCE = 1000000000; /** * Method to register location updates with a desired location provider. If the requested * provider is not available on the device, the app displays a Toast with a message referenced * by a resource id. * * @param provider Name of the requested provider. * @param errorResId Resource id for the string message to be displayed if the provider does * not exist on the device. * @return A previously returned {@link android.location.Location} from the requested provider, * if exists. */ public static Location requestUpdatesFromProvider(LocationManager locationManager, LocationListener locationListener, final String provider, final int errorResId) { Location location = null; if (locationManager.isProviderEnabled(provider)) { locationManager.requestLocationUpdates(provider, RUN_ONCE, RUN_ONCE, locationListener); location = locationManager.getLastKnownLocation(provider); } return location; } }