在 BroadcastReceiver 中使用 containsLocation多边形地理围栏

问题描述

我是编程和这个社区的新手,但我们可以在 broadcastReceiver 中实现 GoogleMaps.Util.polyUtil - containsLocation 方法吗?

我做了 2 个演示应用程序,第一个是学习 polygon(姑且称之为 appsA)。 AndroidCoding 的代码作为参考 https://www.youtube.com/watch?v=_Sx45CbBsoA

第二个是学习地理围栏(appsB)。我在这里使用你的真实代码https://www.youtube.com/watch?v=nmAtMqljH9M&list=PLdHg5T0SNpN3GBUmpGqjiKGMcBaRT2A-m&index=10

仅供参考>

问题:

我正在尝试从 appsA 实现 containsLocation... https://i.stack.imgur.com/AlWVo.png 其中 currLoc 是 LastLocation 的 LatLng,latLngList 是 polygon 的 ArrayList。

在appsB中进入broadcastReceiver... https://i.stack.imgur.com/GMQvt.png

我已经尝试寻找有关此问题的解决方案,但没有任何工作/相关.. 我正在考虑将 polygon LatLng 的 ArrayList 传递到 broadcastReceiver -> 获取当前位置坐标 -> 最后使用 containsLocation

这是代码

在 MapsActivity 上初始化变量

    List<LatLng> latLngList = new ArrayList<>();
    List<Marker> markerList = new ArrayList<>();

地图活动

Geofence geofence = geofenceHelper.getGeofence(GEOFENCE_ID,latLng,radius,Geofence.GEOFENCE_TRANSITION_ENTER |
                Geofence.GEOFENCE_TRANSITION_DWELL);
        GeofencingRequest geofencingRequest = geofenceHelper.getGeofencingRequest(geofence);

        PendingIntent pendingIntent = geofenceHelper.getPendingIntent();

地理围栏助手

    public PendingIntent getPendingIntent(){
        if(pendingIntent!= null){
            return pendingIntent;
        }

        Intent intent = new Intent(this,GeofencebroadcastReceiver.class);
        pendingIntent = PendingIntent.getbroadcast(this,2607,intent,PendingIntent.FLAG_UPDATE_CURRENT);
        return pendingIntent;
    }

广播接收器

        int transitionType = geofencingEvent.getGeofenceTransition();

        switch(transitionType){
            case Geofence.GEOFENCE_TRANSITION_ENTER:
//                it should look like this
//                boolean contains = polyUtil.containsLocation(currLoc,latLngList,true );
//                if(contains)
                Toast.makeText(context,"GEOFENCE TRANSITION ENTER",Toast.LENGTH_SHORT).show();
                break;

我想问的是:

  1. 我可以将 ArrayList 传递给 broadcastReceiver 吗?
  2. 可以这样做吗?或者有更好的解决方案吗?

参考玛丽安在Android: Build Polygonal Shape Geofence中的回答

先谢谢了

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...