Geo Fencing с использованием GeoFire только обнаружение onKeyMoved - PullRequest
0 голосов
/ 07 марта 2019

Я пытаюсь реализовать Geo Fencing с GeoFire в приложении для Android.

Работает, но с проблемой.Когда местоположение пользователя находится внутри области геозоны, выполняется метод onKeyMoved, но оба других метода onKeyEntered и onKeyExited не запускаются.

Это мой текущий код:

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

        LatLng zona = new LatLng(41.635189,2.163086);
        mMap.addCircle(new CircleOptions()
            .center(zona)
            .radius(500)
        .strokeColor(Color.BLUE)
        .fillColor(0x220000FF)
        .strokeWidth(5.0f)
        );

        GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(zona.latitude,zona.longitude),05.f);

        geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
            @Override
            public void onKeyEntered(String key, GeoLocation location) {
                Log.d("MPI","ENTRA en la zona ");
                sendNotification("MPI",String.format("%s entra en la zona",key));

            }

            @Override
            public void onKeyExited(String key) {
                Log.d("MPI","SALE en la zona ");
                sendNotification("MPI",String.format("%s sale de  la zona",key));
            }

            @Override
            public void onKeyMoved(String key, GeoLocation location) {
                Log.d("MPI","esta en la zona ");

            }

            @Override
            public void onGeoQueryReady() {

            }

            @Override
            public void onGeoQueryError(DatabaseError error) {

            }
        });


    }

    private void sendNotification(String title, String content) {

        Notification.Builder builder = new Notification.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher_round)
                .setContentTitle(title)
                .setContentText(content);
        NotificationManager manager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
        Intent intent = new Intent(this, MapsActivity.class);
        PendingIntent contenIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_IMMUTABLE);
        builder.setContentIntent(contenIntent);
        Notification notification = builder.build();
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.defaults |=Notification.DEFAULT_SOUND;

        manager.notify(new Random().nextInt(),notification);






    }

Может бытьВы можете найти что-то не так на этом.

...