get Geography LocationManager - Android android.location

Android examples for android.location:LocationManager

Description

get Geography LocationManager

Demo Code

import android.content.Context;
import android.location.Location;
import android.location.LocationManager;

public class Main {

  public static void getGeography(Context context, double latitude, double longitude) {
    LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
      Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
      if (location != null) {
        latitude = location.getLatitude();
        longitude = location.getLongitude();
      }//w  w  w.  jav a  2 s  .c o  m
    }
  }
}

Related Tutorials