Android examples for Map:Location
get Local Location
//package com.java2s; import android.content.Context; import android.location.Criteria; import android.location.Location; import android.location.LocationManager; public class Main { public static Location getLocalLocation(Context context) { Location location = null; try {/*www.j a v a 2 s . c om*/ //LocationManager LocationManager locationManager = (LocationManager) context .getSystemService(Context.LOCATION_SERVICE); 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 = locationManager.getBestProvider(criteria, true); // location = locationManager.getLastKnownLocation(provider); System.out.println("?:" + location.getLongitude()); System.out.println(":" + location.getLatitude()); } catch (Exception e) { e.printStackTrace(); } return location; } }