我有一个名为 spotCoordinates
的地点的 GPS 坐标,以及一个圆心坐标 this.state.center
和一个以公里为单位的半径 this.state.radius
。
我正试图制作一个方法来检查 spotCoordinates
是否在圆内,但我不知道如何将半径添加到坐标中,以及如何检查它是否真的在圆内。如果是一个正方形的话就更容易了。
calculateParkingSpotsInTheArea = () => {
this.state.parkingSpots.map(spot => {
let spotCoordinates = spot.coordinates;
console.log(spotCoordinates, this.state.center, this.state.radius);
// Calculate if the parking spot is inside the circle
});
}
例如在控制台中打印的值 spotCoordinates = [41.5408446218337, -8.612296123028727] center = {lat: 41.536558, lng: -8.627487} radius = 25
需要帮助吗?
41.5408446218337, -8.612296123028727
是一个点,而41.536558, lng: -8.627487
是另一个点,对吗? - user37832430.0021208675369022113
。我怎么知道它是在内部还是外部呢? - user12361681