<分区>
我想知道如何检查给定点是否在另一个固定点的一定公里半径内?
<分区>
我想知道如何检查给定点是否在另一个固定点的一定公里半径内?
最佳答案
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/