栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

除了Android API之外,是否还有其他用于计算Geofence违规的API

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

除了Android API之外,是否还有其他用于计算Geofence违规的API

您可以自己实现它,而无需使用任何框架,这非常容易…

我假设您要检查您是否在圆形地理围栏内。

为此,只需计算圆心与您的位置之间的距离(经度,纬度)。如果距离小于圆半径,则说明您在地理围栏内,否则就在地理围栏外。

像这样:

    boolean checkInside(Circle circle, double longitude, double latitude) {        return calculateDistance( circle.getLongitude(), circle.getLatitude(), longitude, latitude        ) < circle.getRadius();}

要计算两点之间的距离,可以使用以下方法:

double calculateDistance(  double longitude1, double latitude1,   double longitude2, double latitude2) {    double c =         Math.sin(Math.toRadians(latitude1)) *        Math.sin(Math.toRadians(latitude2)) + Math.cos(Math.toRadians(latitude1)) * Math.cos(Math.toRadians(latitude2)) * Math.cos(Math.toRadians(longitude2) -      Math.toRadians(longitude1));    c = c > 0 ? Math.min(1, c) : Math.max(-1, c);    return 3959 * 1.609 * 1000 * Math.acos(c);}

该公式称为Haversine公式。它考虑了地球的弯曲。结果以米为单位。

我也在博客上描述了它:

  • 用于检查地理围栏圆(还描述了两点之间的距离计算):http : //stefanbangels.blogspot.be/2014/03/point-geo-fencing-sample-pre.html

  • 用于检查地理栅栏多边形:http ://stefanbangels.blogspot.be/2013/10/geo-fencing-sample-pre.html



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/446861.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号