当前位置: 首页 > 知识库问答 >
问题:

利用公共面积处理多个土工墙过渡

林哲茂
2023-03-14

如果我有这两个土工篱笆,注册这些土工篱笆后,当我进入或退出这些圆周时,我应该得到通知。然而,我不希望我的应用程序发送一个通知,如果我移动通过公共区域,即从一个圆圈到另一个。

有可能吗?如果是的话,那又是怎样做的呢?

共有1个答案

吉毅
2023-03-14

您必须使用一个类来监视您的击剑:

public class GeofenceReceiver extends BroadcastReceiver {
    Context context;

    Intent broadcastIntent = new Intent();

    @Override
    public void onReceive(Context context, Intent intent) {
        this.context = context;

        broadcastIntent.addCategory(GeofenceUtils.CATEGORY_LOCATION_SERVICES);

        if (LocationClient.hasError(intent)) {
            handleError(intent);
        } else {
            handleEnterExit(intent);
        }
    }

    private void handleError(Intent intent){
        // Get the error code
        int errorCode = LocationClient.getErrorCode(intent);

        // Get the error message
        String errorMessage = LocationServiceErrorMessages.getErrorString(
                context, errorCode);

        // Log the error
        Log.e(GeofenceUtils.APPTAG,
                context.getString(R.string.geofence_transition_error_detail,
                        errorMessage));

        // Set the action and error message for the broadcast intent
        broadcastIntent
                .setAction(GeofenceUtils.ACTION_GEOFENCE_ERROR)
                .putExtra(GeofenceUtils.EXTRA_GEOFENCE_STATUS, errorMessage);

        // Broadcast the error *locally* to other components in this app
        LocalBroadcastManager.getInstance(context).sendBroadcast(
                broadcastIntent);
    }


    private void handleEnterExit(Intent intent) {
        // Get the type of transition (entry or exit)
        int transition = LocationClient.getGeofenceTransition(intent);

        // Test that a valid transition was reported
        if ((transition == Geofence.GEOFENCE_TRANSITION_ENTER)
                || (transition == Geofence.GEOFENCE_TRANSITION_EXIT)) {

            // Post a notification
            List<Geofence> geofences = LocationClient
                    .getTriggeringGeofences(intent);
            String[] geofenceIds = new String[geofences.size()];
            String ids = TextUtils.join(GeofenceUtils.GEOFENCE_ID_DELIMITER,
                    geofenceIds);
            String transitionType = GeofenceUtils
                    .getTransitionString(transition);

            for (int index = 0; index < geofences.size(); index++) {
                Geofence geofence = geofences.get(index);
                ...do something with the geofence entry or exit. I'm saving them to a local sqlite db

            }
            // Create an Intent to broadcast to the app
            broadcastIntent
                    .setAction(GeofenceUtils.ACTION_GEOFENCE_TRANSITION)
                    .addCategory(GeofenceUtils.CATEGORY_LOCATION_SERVICES)
                    .putExtra(GeofenceUtils.EXTRA_GEOFENCE_ID, geofenceIds)
                    .putExtra(GeofenceUtils.EXTRA_GEOFENCE_TRANSITION_TYPE,
                            transitionType);

            LocalBroadcastManager.getInstance(MyApplication.getContext())
                    .sendBroadcast(broadcastIntent);

            // Log the transition type and a message
            Log.d(GeofenceUtils.APPTAG, transitionType + ": " + ids);
            Log.d(GeofenceUtils.APPTAG,
                    context.getString(R.string.geofence_transition_notification_text));

            // In debug mode, log the result
            Log.d(GeofenceUtils.APPTAG, "transition");

            // An invalid transition was reported
        } else {
            // Always log as an error
            Log.e(GeofenceUtils.APPTAG,
                    context.getString(R.string.geofence_transition_invalid_type,
                            transition));
        }
    }

    //Posts a notification in the notification bar when a transition 
    private void sendNotification(String transitionType, String locationName) {

        // Create an explicit content Intent that starts the main Activity
        Intent notificationIntent = new Intent(context, MainActivity.class);

        // Construct a task stack
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);

        // Adds the main Activity to the task stack as the parent
        stackBuilder.addParentStack(MainActivity.class);

        // Push the content Intent onto the stack
        stackBuilder.addNextIntent(notificationIntent);

        // Get a PendingIntent containing the entire back stack
        PendingIntent notificationPendingIntent = stackBuilder
                .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

        // Get a notification builder that's compatible with platform versions
        // >= 4
        NotificationCompat.Builder builder = new NotificationCompat.Builder(
                context);

        // Set the notification contents
        builder.setSmallIcon(R.drawable.ic_notification)
                .setContentTitle(transitionType + ": " + locationName)
                .setContentText(
                        context.getString(R.string.geofence_transition_notification_text))
                .setContentIntent(notificationPendingIntent);

        // Get an instance of the Notification manager
        NotificationManager mNotificationManager = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);

        // Issue the notification
        mNotificationManager.notify(0, builder.build());
    }

您应该为希望监视的每个区域创建侦听器,比如listener1和Listener2。要优化这两个区域并将其集成,最好的方法是使用MongoDB创建网格,在这种情况下,当您构建网格时,它甚至允许您集成两个以上的点。

假设你要得到一个多边形,它是一些后点的形式,那么你可以生成一个网格,如下所示:

# Method to get the min and max values for the polygon  
def get_bounding_box(coords)
# get max and min coords
max = coords.inject({lat:0, lon:0}) do |max, c|
max[:lon] = c[0] if c[0] > max[:lon]
max[:lat] = c[1] if c[1] > max[:lat]
max
end
min = coords.inject({lat:MAX_LAT, lon:MAX_LON}) do |min, c|
min[:lon] = c[0] if c[0] < min[:lon]
min[:lat] = c[1] if c[1] < min[:lat]
min
end
# add a little padding to the max and min
max.each {|k, v| max[k] += 1 }
min.each {|k, v| min[k] -= 1 }

{min: min, max: max}
end

def generate_grid(bounds)
lon_range = bounds[:min][:lon]...bounds[:max][:lon]
lat_range = bounds[:min][:lat]...bounds[:max][:lat]

grid = []
lon_range.each do |lon|
lat_range.each do |lat|
grid << [lon + 0.25, lat + 0.25]
grid << [lon + 0.25, lat + 0.75]
grid << [lon + 0.75, lat + 0.25]
grid << [lon + 0.75, lat + 0.75]
end
end

grid
end

这种方法允许您使用智能电网实现非常高效的地理隔离,以监控目标区域:

最近,MongoDB还增加了对Android的支持,从而为您的Android应用程序后端集成提供了一个简单的方法。事实上,使用智能分布式数据开发地理围栏的应用预计会越来越多。

 类似资料:
  • 我想计算一个随机多边形的面积和一个随机多面体的体积。谷歌搜索让我找到了镶嵌和蒙特卡罗方法。然而,我只感兴趣的是一个精确的计算,而不是通过收敛的近似值。可能有人知道确切的公式,或有一个网页的链接,这样的公式被描述? 对于奇异多边形或多面体,不需要用到这些公式。如果它们适用于简单的(不相交的边)凸形状,我已经很满意了。我只想使用一个顶点坐标列表或(可能按特定顺序排列)。 我能够阅读、、和。因此,用这些

  • 这里手头的问题是,在Game类中有一个公共SpriteBatch是不是一个好主意,然后所有屏幕都使用它。这将避免在活动屏幕发生变化时重新分配对象。 然而,我看到人们在每一个屏幕上都使用新的和私有的SpriteBatchs。为什么人们要这样做?我是不是漏了什么?

  • 我的应用程序需要2个防火墙,一个用于管理员,另一个用于用户。在my security.yml I config中: 我不知道这个配置是否正确。当我从主区域登录时,一切都正常,但当我从管理员登录时,它会将我重定向到主路径,而不是默认的目标路径。我尝试将提供程序更改为自定义提供程序(例如在内存中)以重新检查管理员防火墙,但我仍然通过用户从fos_userbundle提供程序登录。你能帮助我吗?

  • 我正在尝试从我们的网络访问cloud Elasticsearch安装,这需要使用外部请求的代理。这是我用来传递Elasticsearch凭据和代理设置的代码片段: CredentialsProvider CredentialsProvider=new BasicCredentialsProvider();CredentialsProvider.SetCredentials(AuthScope.An

  • 问题内容: 我已经在javaworld.com上阅读了两篇文章(1)(2),有关所有类字段应如何为私有,并且getter / setter方法同样糟糕。对象应该对它拥有的数据进行操作,而不是允许对其进行访问。 我目前正在为Connect Four 进行大学作业。在设计程序时,玩游戏的特工需要访问董事会的状态(以便他们可以决定移动的方向)。他们还需要将此举动传递给游戏,以便可以将其确认为合法举动。在

  • 本文向大家介绍多个jQuery版本共存的处理方案,包括了多个jQuery版本共存的处理方案的使用技巧和注意事项,需要的朋友参考一下 如何在一个页面上让多个jQuery共存呢?比如jquery-1.5和jquery-1.11。 你可能会问,为什么需要在一个页面上让多个jQuery共存?直接引用最新版本的jQuery不行吗? 答案是,不行。因为现实生活是非常残酷的。举个栗子: 现有网站已经引用了jQu