Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.location.Location; import android.location.LocationManager; import java.util.List; public class Main { public static Location getLastKnownLocation(Context context) { LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); List<String> providers = manager.getProviders(true); for (String provider : providers) { Location location = manager.getLastKnownLocation(provider); if (location != null) { return location; } } // At this point we've done all we can and no location is returned return null; } }