Get Longitude from Location - Android Hardware

Android examples for Hardware:Gps

Description

Get Longitude from Location

Demo Code


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

public class Main {
  private static Location _location;

  private static Location GetLastKnownLocation(Context context) {

    if (_location == null) {
      LocationManager loctionManager;/*from  www .  j  av a 2s  . c o  m*/
      String contextService = Context.LOCATION_SERVICE;
      loctionManager = (LocationManager) context.getSystemService(contextService);

      Criteria criteria = new Criteria();
      criteria.setAccuracy(Criteria.ACCURACY_FINE);// 
      criteria.setAltitudeRequired(false);// 
      criteria.setBearingRequired(false);// 
      criteria.setCostAllowed(true);// 
      criteria.setPowerRequirement(Criteria.POWER_LOW);// 
      String provider = loctionManager.getBestProvider(criteria, true);

      _location = loctionManager.getLastKnownLocation(provider);
    }
    return _location;
  }
}

Related Tutorials