是否有任何用于计算除Android API之外的Geofence破坏的API [英] Is there any API for calculating Geofence breach other than Android API's

查看:98
本文介绍了是否有任何用于计算除Android API之外的Geofence破坏的API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算后端的地理围栏破坏和行驶距离计算。这是我第一次使用谷歌API。我在网上找到的只是Android版。是否有任何特定于常规计算的API。

I would like to calculate geofence breach and driving distance calculation in the backend. This is my first time using the google API. All I find in the web is are for Android. Is there any API specific to regular calculations.

推荐答案

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

You can implement it yourself, without using any frameworks, it's very easy...

我认为你想要检查你是否在圈子地理围栏内。

I presume that you want to check if you're inside a circle geofence or not.

To这样做,只需计算圆心和你的位置(经度,纬度)之间的距离。如果距离小于你的圆半径,那么你就在地理围栏内,否则你就在地理围栏之外。

To do this, just calculate the distance between the center of the circle and your location (longitude, latitude). If the distance is smaller than your circle radius, then you're inside the geofence, otherwise you're outside the geofence.

像这样:

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

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

To calculate the distance between two points, you can use this:

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公式。
它考虑了地球的曲线。
结果以米为单位。

This formula is called the Haversine formula. It takes into account the earths curvation. The results are in meters.

我也在我的博客上描述过:

I've also described it on my blog:

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

for checking geofencing polygons: http://stefanbangels.blogspot.be/2013/10/geo-fencing-sample-code.html

这篇关于是否有任何用于计算除Android API之外的Geofence破坏的API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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