计算经度和纬度的半径 [英] Calculating a radius with longitude and latitude

查看:77
本文介绍了计算经度和纬度的半径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试确定两个位置(每个位置都有各自的纬度和经度值)是否在一定距离内,例如3英里半径内.我有两个值代表每个位置的纬度和经度.

I am trying to determine if two locations (each with their own latitude and longitude values) are within a certain distance of each other, a 3 mile radius for example. I have double values to represent the latitude and longitude of each location.

//Location 1
Double lattitude1 = 40.7143528;
Double longitude1 = -74.0059731;

//Location 2
Double lattitude2 = 33.325;
Double longitude2 = 44.422000000000025;

我想知道如何确定这两个位置是否在彼此的半径内,因为我不确定如何使用这种类型的值来做到这一点.

I am wondering how I would determine if these two locations are within each others radius or not because I am not entirely sure how to do this with this type of value.

推荐答案

请参见大圆圈距离

double CoordDistance(double latitude1, double longitude1, double latitude2, double longitude2)
{
    return 6371 * Math.acos(
        Math.sin(latitude1) * Math.sin(latitude2)
        + Math.cos(latitude1) * Math.cos(latitude2) * Math.cos(longitude2 - longitude1));
}

如果您的经度和纬度以度为单位,则将它们转换为弧度.

If your latitude and longitude are in degrees convert them to radians.

这篇关于计算经度和纬度的半径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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