Example usage for android.location Geofence.Builder Geofence.Builder

List of usage examples for android.location Geofence.Builder Geofence.Builder

Introduction

In this page you can find the example usage for android.location Geofence.Builder Geofence.Builder.

Prototype

Geofence.Builder

Source Link

Usage

From source file:com.kylemsguy.fishyfishes.MainActivity.java

public static boolean actuallyRunCheck(final MainActivity activity) {
    if (!activity.playServicesConnected)
        return false;
    Location curr = activity.getCurrentLocation();
    if (curr == null)
        return false;
    if (!PreferenceManager.getDefaultSharedPreferences(activity).getBoolean("location_spoof_enable", false)) {
        me.setPosition(new LatLng(curr.getLatitude(), curr.getLongitude()));

    }//from ww  w . j  av  a 2 s  . co  m
    System.out.println(curr.toString());
    ArrayList<Placemark> marks = getInRangePlaceMarks(curr, getAlertRadiusMeters(activity) * 10);
    final List<Geofence> fences = new ArrayList<Geofence>(marks.size() + 1);
    for (Placemark mark : marks) {
        fences.add(new Geofence.Builder().setRequestId(mark.name)
                .setCircularRegion(mark.lat, mark.lon, getAlertRadiusMeters(activity))
                .setExpirationDuration(Geofence.NEVER_EXPIRE)
                .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER).build());
    }
    final PendingIntent pendingIntent = activity.getGeofencePendingIntent();
    LocationServices.GeofencingApi.removeGeofences(activity.mGoogleApiClient, pendingIntent)
            .setResultCallback(new ResultCallback<Status>() {
                public void onResult(Status s) {
                    if (fences.size() == 0)
                        return;
                    GeofencingRequest.Builder builder = new GeofencingRequest.Builder();
                    builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER);
                    builder.addGeofences(fences);
                    final GeofencingRequest request = builder.build();
                    LocationServices.GeofencingApi.addGeofences(activity.mGoogleApiClient, request,
                            pendingIntent);
                    System.out.println("added geofences: " + fences);
                }
            });
    return false;
}