Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.content.Context;

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

public class Main {

    public static Location getLocation(Context context) {
        try {
            LocationManager locMan = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
            Location location = locMan.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            if (location == null) {
                location = locMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
            }
            return location;
        } catch (Exception e) {
        }
        return null;
    }
}