如何将应用程序可用性限制在特定地理区域 ANDROID [英] How to restrict app usability to a certain geographical area ANDROID

查看:45
本文介绍了如何将应用程序可用性限制在特定地理区域 ANDROID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想定义一个地理边界,在该边界之外,应用程序将拒绝工作.我已经知道如何用两个经纬度对的正方形来做到这一点:

I want to define a geographical boundary outside of which, the app will refuse to work. I already know how to do this with a square bound by two lat/long pairs:

 if ((dLAT.doubleValue() > 35.309171) || (dLAT.doubleValue() < 35.226442) || (dLON.doubleValue() < -92.790165) || (dLON.doubleValue() > -92.707081))
    {
        LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this);

        localBroadcastManager.sendBroadcast(new Intent("killapp"));
    }

我也了解地理围栏...或者足以知道,使用地理围栏,区域被定义为以单个点为半径的圆.

I also know about geofencing... or enough to know that with geofencing, areas are defined as circles with a radius from a single point.

但就像我说的,我想定义一个符合现实的边界:

But like I said I would like to define a boundary that matches reality:

例如,如果有一个应用程序被设计为在用户位于堪萨斯州边界之外时不起作用,那么定义 RADIUS 就不能令人满意,因为堪萨斯州不是圆形的,其边界是摆动.

For example, if there was an app that was designed NOT to work if the user is outside the border of Kansas, it would not be satisfactory to define a RADIUS, as the state of Kansas is not circular, and its border is wiggly.

我碰巧为此使用了 Android,但我怀疑这对于这个问题是否真的很重要.

I happen to be using Android for this, but I doubt that really matters for this question.

感谢您的帮助!

推荐答案

这比想象的要容易得多:

This is much easier than one thinks:

将区域定义为多边形,在经纬度坐标中有 N 个点.

define the region(s) as polygon, having N points in longitude, latitude coordinates.

在多边形方法中使用点:

Use a point in polygon method:

点入多边形算法

要测试当前点是否在多边形的外部,上面的代码使用 x,y 坐标.只需使用经度而不是 x 和纬度作为 y.
当该区域跨越北极或南极时,以及当它跨越基准面限制(经度边界 = -180 到 180)时,代码可能不起作用,但没有人在那里使用您的应用程序.

To test if the current point is inside our outside of the polygon, the code above is using x,y coordinates. Just use longitude instead of x and latitude as y.
The code may not work when the region crosses the North or South pole, and when it crosses the datum limit (border of longitude = -180 to 180) but nobody uses your app there.

尽管不能总是使用设计的公式在 x,y(笛卡尔)平面上工作,但它也适用于球面纬度、经度和坐标.

Altough one cannot always use formulas desigend to work in the x,y (cartesian) plane, it works here for spherical lat,lon, coordinates too.

这篇关于如何将应用程序可用性限制在特定地理区域 ANDROID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆