Android examples for android.location:GPS
get GPS Location
import android.content.Context; import android.location.Criteria; import android.location.Location; import android.location.LocationManager; public class Main { /**/*from w ww . ja v a 2 s. c om*/ * <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> * <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> * * @param context * @return */ public static Location getGPSLocation(Context context) { LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setCostAllowed(false); criteria.setAccuracy(Criteria.ACCURACY_COARSE); String providerName = locationManager.getBestProvider(criteria, true); if (providerName != null) { Location location = locationManager.getLastKnownLocation(providerName); return location; } else { return null; } } }