OnKeyEntered не получает триггер - PullRequest
0 голосов
/ 29 марта 2020

Я хочу создать приложение, в котором уведомление запускается при входе устройства в геозону. OnKeyEntered не запускается в моем коде, мое текущее местоположение обновляется в базе данных реального времени.

 public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    // goToLocationZoom(39.008224,-76.8984527, 15);

    mMap.getUiSettings().setZoomControlsEnabled(true);

    if (fusedLocationProviderClient != null)
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                // TODO: Consider calling
                //    Activity#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 Activity#requestPermissions for more details.
                return;
            }
        }
        fusedLocationProviderClient.requestLocationUpdates(locationRequest, locationCallback, Looper.myLooper());

        //goequery for locations


   // for(LatLng latLng:WorkArea)
    //{
        if(WorkAreaCur!=null) {
            GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(WorkAreaCur.latitude, WorkAreaCur.longitude), 0.5); //500m
            geoQuery.addGeoQueryEventListener(MapsActivity.this);
        }
    //}
        //Toast.makeText(MapsActivity.this," "+cnt,Toast.LENGTH_LONG).show();

}

Я вызвал set location здесь и queryAtLocation в функции onMapReady

private void buildLocationCallback() {
    locationCallback = new LocationCallback() {
        @Override
        public void onLocationResult(final LocationResult locationResult) {
            if (mMap != null) {

                geoFire.setLocation("YOU", new GeoLocation(locationResult.getLastLocation().getLatitude(),
                        locationResult.getLastLocation().getLongitude()), new GeoFire.CompletionListener() {
                    @Override
                    public void onComplete(String key, DatabaseError error) {
                        if (currentuser != null) currentuser.remove();

                        currentuser = mMap.addMarker(new MarkerOptions()
                                .position(new LatLng(locationResult.getLastLocation().getLatitude(),
                                        locationResult.getLastLocation().getLongitude()))
                                .title("YOU")
                        );
                        //move camera
                        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(currentuser.getPosition(), 12.0f));

                    }
                });
            }

        }
    };
}
...