首页 > 解决方案 > 我需要有关 Android 上的 Geofence 或 Geofire 的帮助

问题描述

每当我的设备进入地理围栏时,我希望根据场景sendNotificationsToEveryone()触发或触发。sendNotificationsToEveryoneExit()

这是我的代码的函数触发部分:

geoQueryArray[geoFireCount] = geoFire.queryAtLocation(new GeoLocation(geofirelocations.latitude, geofirelocations.longitude), 0.1f);
            geoQueryArray[geoFireCount].addGeoQueryEventListener(new GeoQueryEventListener() {
                @Override
                public void onKeyEntered(String key, GeoLocation location) {
                    sendNotificationsToEveryone(fcm_tokens_list, geoName);
                }

                @Override
                public void onKeyExited(String key) {
                    sendNotificationsToEveryoneExit(fcm_tokens_list,geoName);
                }

                @Override
                public void onKeyMoved(String key, GeoLocation location) {
                    Log.d("MOVE", String.format("%s move within the dangerous area [%f/%f]", key, location.latitude, location.longitude));
                    //sendNotificationsExit(fcm_tokens_list);
                }

                @Override
                public void onGeoQueryReady() {

                }

                @Override
                public void onGeoQueryError(DatabaseError error) {
                    Log.d("ERROR", ""+error);
                }
            });
            geoFireCount++;

这是我的设备代码,当它进入地理围栏时,它应该触发 sendNotifications 函数:

  final double latitude = Double.parseDouble(part1);
  final double longitude = Double.parseDouble(part2);

    geoFire1.setLocation("You", new GeoLocation(latitude, longitude), new GeoFire.CompletionListener() {
        @Override
        public void onComplete(String key, DatabaseError error) {
            if (mCurrent != null)
                mCurrent.remove();

            BitmapDescriptor deviceIcon = BitmapDescriptorFactory.fromResource(R.drawable.watchdevice);

            mCurrent = mMap.addMarker(new MarkerOptions()
                    .position(new LatLng(latitude, longitude))
                    .title("GPS Device").icon(deviceIcon));
            LatLng coordinate = new LatLng(latitude, longitude);
            CameraUpdate yourLocation = CameraUpdateFactory.newLatLngZoom(coordinate, 12);
            mMap.animateCamera(yourLocation);
        }
    });

此代码在同一个文件中,我想知道如何编辑geoQueryArray[]以包含设备,当它进入地理围栏时,sendNotications功能将被触发。

标签: javaandroidgpsdevicegeofire

解决方案


推荐阅读