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

查看:231
本文介绍了如何将应用程序可用性限制在特定地理区域内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天全站免登陆