Transiciones de transición de geofence de Android
Estoy construyendo una aplicación que incluye geofences googles, que he creado con las transiciones ENTER y EXIT . El problema se produce al activar " Location ", cuando dentro de mi geofence, que desencadena las dos transiciones, cuando sólo la transición ENTRAR debe disparar. He fijado ENTER y EXIT como intitialTrigger()
.
¿Cómo esto puede ser posible?
- ¿Cómo puedo implementar un geocodificador sin conexión para una sola ciudad utilizando datos OSM en android?
- Android - Geocoder.getFromLocationName () no funciona en el dispositivo ICS
- Android: Nexus One - Geocoder causa IOException - funciona perfectamente con otros dispositivos y emuladores
- ¿Cómo notificar al usuario cuando entra en alguna región usando Geoloqi API?
- Android - Geocoder no obtener la cadena de direcciones
¿Es una falla en el google api o he hecho algo mal en el constructor. Gracias por adelantado.
@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(); }
- Android geopoint de la localidad / localidad
- Cómo obtener latitud y longitud de la dirección en android
- Android límite máximo para geofences?
- android obtener el nombre de ubicación actual
- Geocodificación inversa - Servicio No disponible - Reiniciar el dispositivo que no resuelve definitivamente - criticar mi geocodificación inversa manual
- ¿Cuál es la mejor manera de interpretar la ubicación del usuario junto a Geocoder
- ¿Se eliminan las Geofencias de Android si la aplicación es eliminada por el usuario?
- Android Geocoder.getLocationFromName () throws IOException: Servicio no disponible en Device
Esto podría ser un error extraño en la parte de Google Geofence APIs. Además, es un poco extraño tener los eventos ENTER y EXIT como disparadores iniciales. Aquí hay una solución fácil para llamar dinámicamente setInitialTrigger()
, y evitar esto por completo. Antes de llamar a createGeoFences()
, obtenga un punto GPS y compruebe la distancia desde ese punto hasta el punto central de la geofencia. Si se encuentra fuera de la geofence, pase un valor para establecer el desencadenador inicial en GEOFENCE_TRANSITION_ENTER
, de lo contrario, GEOFENCE_TRANSITION_EXIT
en GEOFENCE_TRANSITION_EXIT
.
En cuanto a por qué está haciendo esto, aquí está mi pensamiento en él, aunque no lo he probado. Google puede estar recibiendo la última ubicación conocida, que podría estar fuera de la geofence inicialmente, registrando así el evento GEOFENCE_TRANSITION_EXIT
. Entonces comenzará su pila de la localización, considera que el teléfono está realmente dentro del geofence, después registra el acontecimiento de GEOFENCE_TRANSITION_ENTER
.
Necesita registrar un IntentService que pueda manejar los disparadores
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)); }
Explicado aquí: http://developer.android.com/training/location/geofencing.html
Si usted necesita saber si usted está dentro de un geofence usted podría hacer un bucle de la lista actual de geofence ubicaciones y comprobar si uno de ellos es cerca de suficiente para disparar?
Algo como esto:
public Location insideGeofenceLocation(Location currentLocation, ArrayList<Location> listOfGeofenceLocations, float triggerRadius) { for (Location geoFenceLocation : listOfGeofenceLocations) { if (currentLocation.distanceTo(geoFenceLocation) < triggerRadius) return geoFenceLocation; } return null; }
Comprobar la ubicación actual:
Location geofenceLocation = insideGeofenceLocation(locationClient.getLastLocation(), listOfGeofenceLocations, TARGET_RADIUS); if(geofenceLocation!=null){ // TODO: update }
- Estoy recibiendo error de representación en el último estudio de android cuando intento ver la vista previa de una actividad
- Convertir JPG a PDF