java - 在 BroadcastReceiver(多边形地理围栏)中使用 containsLocation
问题描述
我是编程和这个社区的新手,但我们可以实现GoogleMaps.Util.PolyUtil
- BroadcastReceiver 中的 containsLocation 方法吗?
<仅供参考>
我做了2个演示应用,第一个是学习Polygon(我们称之为appsA)。AndroidCoding 的代码作为参考https://www.youtube.com/watch?v=_Sx45CbBsoA
第二个是学习地理围栏(appsB)。我在这里使用 yoursTRULY 的代码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 是多边形的 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;
我想问的是:
- 我可以将 ArrayList 传递给 BroadcastReceiver 吗?
- 有可能这样做吗?或者有更好的解决方案吗?
参考 Marian 在Android 中的回答:Build Polygonal Shape Geofence
之前谢谢
解决方案
推荐阅读
- java - Java 流:收集流
列出 - python - 如何在 PyQT 小部件中嵌入 Matplotlib 图?
- javascript - 未使用 Javascript 功能删除芯片标签
- acumatica - ACUMATICA BQL 查询
- docker - 如何使用 elixir phoenix 版本和指南中的示例 MyApp.Release.rollback 在 docker 容器中回滚数据库
- react-native - React Native、AzureDevops 和 Fastlane ipa 构建失败
- sql - 所有行的 LISTAGG 并在一次选择中生成哈希
- macos - osx 上的 Ansible ssh-add 输入密码
- python-3.x - 找不到odoo错误字段'architect_ids'
- opencl - 平台 OpenCL 版本和设备有什么不同?