public void onLocationChanged(Location location) { if (location != null) { setLatitude(location.getLatitude()); setLongitude(location.getLongitude()); Geocoder gcd = new Geocoder(context, Locale.getDefault()); List<Address> addresses; try { addresses = gcd.getFromLocation(location.getLatitude(), location.getLongitude(), 1); if (addresses.size() > 0) { // if (addresses.get(0).getLocality() != null) { // System.out.println(addresses.get(0).getLocality()); // CurrentCity = addresses.get(0).getLocality(); Log.e("", addresses.get(0).getCountryCode()); // Log.e("", addresses.get(0).get); // countryCode = addresses.get(0).getCountryCode(); callBack.notify( "", addresses.get(0).getCountryCode() + "-" + addresses.get(0).getLocality()); // } else { // CurrentCity = ""; // } } } catch (IOException e) { e.printStackTrace(); } } }
public static void locationManagerService(LocationManager locationManager) { Criteria criteria = new Criteria(); criteria.setPowerRequirement(Criteria.POWER_HIGH); criteria.setAccuracy(Criteria.ACCURACY_COARSE); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setSpeedRequired(false); criteria.setCostAllowed(true); setProvider(locationManager.getBestProvider(criteria, true)); location = locationManager.getLastKnownLocation(provider); if (location != null) { setLatitude(location.getLatitude()); setLongitude(location.getLongitude()); } }