java - 经纬度 : Check whether a given point of LatLng is within a 5km radius of another point

标签 java android google-maps

<分区>

我想知道如何检查给定点是否在另一个固定点的一定公里半径内?

最佳答案

Location类具有计算点之间距离的方法

第一个选项(使用 distanceTo 方法):

// firstLocation and secondLocation are Location class instances
float distance = firstLocation.distanceTo(secondLocation); // distance in meters

if (distance < 5000) {
    // distance between first and second location is less than 5km
}

第二个选项(使用静态 distanceBetween 方法):

// distance is stored in result array at index 0
float[] result = new float[1];
Location.distanceBetween (startLat, startLng, endLat, endLng, result);

if (result[0] < 5000) {
    // distance between first and second location is less than 5km
}

关于java - 经纬度 : Check whether a given point of LatLng is within a 5km radius of another point,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25281976/

相关文章:

javascript - 如何使用 fitBounds() 覆盖 Google map 初始化的选项;

java - 还需要 rmic 吗?

Android @SuppressWarnings 在语句级别,而不是方法级别

java - 如何删除无用的JSP

android - 当我们从应用程序设置中禁用(撤销)它们时处理权限

android - Xamarin Android 中的 java.lang.NoClassDefFoundError : android. support.v7.app.AppCompatDelegateImplV14

javascript - 向 Google map 添加信息标记

ios - 按下完成按钮时如何添加标记?

java - 为什么在构造函数中赋值时,clone()函数显示不兼容的类型?

java - 以小端方式写一个整数