Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.app.Activity;
import android.content.Context;

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

public class Main {
    public static double[] getLastKnownLocation(Activity a) {
        LocationManager locationManager = (LocationManager) a.getSystemService(Context.LOCATION_SERVICE);
        Criteria criteria = new Criteria();
        String provider = locationManager.getBestProvider(criteria, true);
        System.out.println("provider: " + provider);
        Location location = locationManager.getLastKnownLocation(provider);
        return new double[] { location.getLatitude(), location.getLongitude() };
    }
}