Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.location.Location; import android.location.LocationManager; import java.util.List; public class Main { /** * To be used if you just want a one-shot best last location, iterates over * all providers and returns the most accurate result. */ public static Location getBestLastGeolocation(Context context) { LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); List<String> providers = manager.getAllProviders(); Location bestLocation = null; for (String it : providers) { Location location = manager.getLastKnownLocation(it); if (location != null) { if (bestLocation == null || location.getAccuracy() < bestLocation.getAccuracy()) { bestLocation = location; } } } return bestLocation; } }