每当我的设备进入地理围栏内时,我都希望根据情况触发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
函数将被触发。