Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 *  2014 Brien Coffield
 *
 * This file is subject to the terms and conditions defined in
 * file 'LICENSE', which is part of this source code package.
 */

import android.content.Context;

import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;

public class Main {
    public static Location getLocation(Context context) {
        LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        // Gets the last known location from the best service.
        String bestLocationProvider = locationManager.getBestProvider(new Criteria(), true /*enabled only*/);
        return locationManager.getLastKnownLocation(bestLocationProvider);
    }
}