简体   繁体   English

Android:构建多边形形状地理围栏

[英]Android: Build Polygonal Shape Geofence

According to the API documentation, only Circular shape Geofences allowed: 根据API文档,只有圆形Geofences允许:

https://developers.google.com/android/reference/com/google/android/gms/location/Geofence.Builder https://developers.google.com/android/reference/com/google/android/gms/location/Geofence.Builder

And it's looks for example: https://developer.android.com/training/location/geofencing.html 它的例子如下: https//developer.android.com/training/location/geofencing.html

But I have 4 locations, representing 4 corners of rectangle, and I want my Geofence to be that rectangle. 但我有4个位置,代表矩形的4个角,我希望我的地理围栏是那个矩形。

I want to avoid solution of building my custom location monitoring service extending the functionality of monitoring Geofences, because I think this kind of services are CPU & power consuming... 我想避免构建我的自定义位置监控服务的解决方案,扩展监控Geofences的功能,因为我认为这种服务是CPU和耗电的......

Thanks, 谢谢,

You have to do it by yourself (however I think it's rather senseless - geofences/location services are inaccurate enough to not even be able to alert about circles, don't even think about some other concrete shape). 你必须自己做(但我认为它是相当无意义的 - 地理围栏/位置服务是不准确的,甚至不能提醒圈子,甚至不考虑其他具体的形状)。

Create smallest circular geofence which contains your polygon and if triggered just check if you are in the polygon inside with Google Maps Android API utility library . 创建包含多边形的最小圆形地理围栏,如果触发,只需使用Google Maps Android API实用程序库检查您是否位于多边形内部。

In other words check if you are in white area not in grey: 换句话说,检查您是否处于灰色的白色区域:

在此输入图像描述

The Android Geofencing API only provides support for Circular Geofences. Android Geofencing API仅支持Circular Geofences。 If you want to monitor Polygon shaped geofences then you have to implement it your self. 如果你想要监控多边形的地理围栏,那么你必须自己实现它。

One solution would be something like this: 一个解决方案是这样的:

Get the current location update using Location API. 使用Location API获取当前位置更新。

Now you have polygon shaped geofence. 现在你有了多边形的地理围栏。 You can use ray-casting Algorithm to check if a point is inside the Closed Polygon or not? 您可以使用光线投射算法来检查点是否在闭合多边形内?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM