好的,我有点困惑。
我按如下方式创建聚合:
public class Example_services extends Service {
public static final String BROADCAST_ACTION = "com.guards.anshul.hindguard.CUSTOM_INTENT";
private static final int TWO_MINUTES = 1000 * 60 * 2;
public LocationManager locationManager;
public MyLocationListener listener;
public Location previousBestLocation = null;
public String editTextValue;
Intent intent;
String restoredText;
private final static int MY_PERMISSION_FINE_LOCATION = 101;
@Override
public void onCreate() {
super.onCreate();
intent = new Intent(BROADCAST_ACTION);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
if(editTextValue!=null){
editTextValue = intent.getStringExtra("B");
SharedPreferences.Editor editor = getSharedPreferences("Guard_Id", MODE_PRIVATE).edit();
editor.putString("guard_id", editTextValue);
editor.apply();
}else{
SharedPreferences prefs = getSharedPreferences("Guard_Id", MODE_PRIVATE);
restoredText = prefs.getString("guard_id", null);
}
Toast.makeText(Example_services.this.getApplicationContext(),restoredText,Toast.LENGTH_SHORT).show();
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
listener = new MyLocationListener();
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
Toast.makeText(Example_services.this.getApplicationContext(),"Need Permission",Toast.LENGTH_SHORT).show();
return Service.START_STICKY;
}
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 4000, 0, listener);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 4000, 0, listener);
return Service.START_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
protected boolean isBetterLocation(Location location, Location currentBestLocation) {
if (currentBestLocation == null) {
return true;
}
long timeDelta = location.getTime() - currentBestLocation.getTime();
boolean isSignificantlyNewer = timeDelta > TWO_MINUTES;
boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES;
boolean isNewer = timeDelta > 0;
if (isSignificantlyNewer) {
return true;
} else if (isSignificantlyOlder) {
return false;
}
int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy());
boolean isLessAccurate = accuracyDelta > 0;
boolean isMoreAccurate = accuracyDelta < 0;
boolean isSignificantlyLessAccurate = accuracyDelta > 200;
boolean isFromSameProvider = isSameProvider(location.getProvider(),
currentBestLocation.getProvider());
if (isMoreAccurate) {
return true;
} else if (isNewer && !isLessAccurate) {
return true;
} else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) {
return true;
}
return false;
}
private boolean isSameProvider(String provider1, String provider2){
if(provider1==null){
return provider2 == null;
}
return provider1.equals(provider2);
}
@Override
public void onDestroy() {
// handler.removeCallbacks(sendUpdatesToUI);
super.onDestroy();
Log.v("STOP_SERVICE", "DONE");
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
locationManager.removeUpdates(listener);
}
public static Thread performOnBackgroundThread(final Runnable runnable) {
final Thread t = new Thread() {
@Override
public void run() {
try {
runnable.run();
} finally {
}
}
};
t.start();
return t;
}
public class MyLocationListener implements LocationListener
{
public void onLocationChanged(final Location loc)
{
if(isBetterLocation(loc, previousBestLocation)) {
double v = loc.getLatitude();
double b = loc.getLongitude();
//Log.e("<<a--b>>>>>>",String.valueOf(v)+ String.valueOf(b));
Toast.makeText(getApplicationContext(), String.valueOf(v)+String.valueOf(b), Toast.LENGTH_SHORT).show();
intent.setAction("com.guards.anshul.hindguard.CUSTOM_INTENT");
intent.putExtra("latitude",v);
intent.putExtra("longitude", b);
intent.putExtra("A",restoredText);
intent.putExtra("Provider", loc.getProvider());
sendBroadcast(intent);
}
}
public void onProviderDisabled(String provider)
{
Toast.makeText(getApplicationContext(), "Gps Disabled", Toast.LENGTH_SHORT).show();
}
public void onProviderEnabled(String provider)
{
Toast.makeText( getApplicationContext(), "Gps Enabled", Toast.LENGTH_SHORT).show();
}
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
}
}
现在在此聚合中,我想将范围过滤器应用于此聚合。 (点击价格大于0)。
所以我有点困惑如何实际做到这一点?没有setFilter方法,我会这样做。
任何人都可以帮我这个吗?
答案 0 :(得分:0)
发现自己,这里是如何运作的:
创建过滤器:
$filter = new Filter('paid', new Query\Range('price', ['gt' => 0]));
创建聚合:
$aggregation = new DateHistogram('clicks_by_day', 'date', 'day');
将过滤添加到过滤器:
$aggregation = $filter->addAggregation($aggregation);
最后一步返回应用过滤器的聚合。 Ant按预期工作。