Android geophotography transition triggers

I am creating an application that includes googles geology that I created with the ENTER and EXIT transitions . The problem arises when the " Location " is turned on , when inside my geolocation there is a merger of both transitions, when only the ENTER transition should start. Ive installed both ENTER and EXIT as intitialTrigger().

How is this possible?

This is a bug in the google api or I did something wrong in the builder. Thanks in advance.

@Override
public void onResult(Result result) {
    Status s = result.getStatus();
    Log.d(TAG, "onResult(...)" + s.isSuccess());
    if (!s.isSuccess()) {
        Log.d(TAG, "statuskode = " + s.getStatusCode() +
                "  noget gik galt, sandsynlighvis blev gps slået fra = statuscode 1000");
    }
}

private GeofencingRequest createGeoFences() {
    return new GeofencingRequest.Builder()
            .addGeofence(geoFenceBuilder(Constants.LOCATION_BALLERUP, "ballerup_req_id"))
            .addGeofence(geoFenceBuilder(Constants.LOCATION_AALBORG, "aalborg_req_id"))
            .addGeofence(geoFenceBuilder(Constants.LOCATION_ESBJERG, "esbjerg_req_id"))
            .addGeofence(geoFenceBuilder(Constants.LOCATION_ÅRHUS, "århus_req_id"))
                    //  .addGeofence(geoFenceBuilder(Constants.LOCATION_TAASTRUP, 44))
            .setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER | GeofencingRequest.INITIAL_TRIGGER_EXIT)
            .build();
}

private Geofence geoFenceBuilder(LatLng location, String requestId) {

    return new Geofence.Builder().setCircularRegion(location.latitude, location.longitude, TARGET_RADIUS)
            .setExpirationDuration(Geofence.NEVER_EXPIRE)
            .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT)
            .setRequestId(requestId)
            .setNotificationResponsiveness(NOTIFICATION_DELAY)
            .build();
}
+4
source share
2 answers

- API Google Geofence. , ENTER, EXIT . setInitialTrigger() . createGeoFences(), GPS . , , GEOFENCE_TRANSITION_ENTER, GEOFENCE_TRANSITION_EXIT.

, , , . Google , , GEOFENCE_TRANSITION_EXIT. , , , GEOFENCE_TRANSITION_ENTER.

+2

IntentService,

public class GeofenceTransitionsIntentService extends IntentService {
   ...
protected void onHandleIntent(Intent intent) {

    GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent);   
    // Get the transition type.
    int geofenceTransition = geofencingEvent.getGeofenceTransition();

    // Test that the reported transition was of interest.
    if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER ) {
        //TODO: on Transition Enter
    }else if(geofenceTransition == Geofence.GEOFENCE_TRANSITION_EXIT){
        //TODO: on Transition Exit
    }else{
      Log.e(GEOFENCE, "Event not handled",
                geofenceTransition));
    }

: http://developer.android.com/training/location/geofencing.html

, , , , ?

- :

public Location insideGeofenceLocation(Location currentLocation, ArrayList<Location> listOfGeofenceLocations, float triggerRadius) {
    for (Location geoFenceLocation : listOfGeofenceLocations) {
        if (currentLocation.distanceTo(geoFenceLocation) < triggerRadius)
            return geoFenceLocation;
    }
    return null;
}

:

Location geofenceLocation = insideGeofenceLocation(locationClient.getLastLocation(), listOfGeofenceLocations, TARGET_RADIUS);
if(geofenceLocation!=null){
    // TODO: update
}
0

Source: https://habr.com/ru/post/1619832/


All Articles