私はphversでHaversineの式を使用して2つのポストコード間の距離を計算しようとしています。これまで私は距離を解決する関数を作成しました。私のデータベーステーブルは「postcode」と呼ばれ、フィールドは「postcode_id」、「postcode」、「lat」、「lng」です。Haversine公式を使用してPHPの2つのポストコード間の距離を計算する
<script>
function getDistance($latitude1, $longitude1, $latitude2, $longitude2) {
$earth_radius = 6371;
$postLat = deg2rad($latitude2 - $latitude1);
$postLon = deg2rad($longitude2 - $longitude1);
$a = sin($postLat/2) * sin($postLat/2) + cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * sin($postLon/2) * sin($postLon/2);
$c = 2 * asin(sqrt($a));
$d = $earth_radius * $c;
return $d;
}
</script>
<?php
$postcode_qry = mysqli_query($connect, "SELECT *,(((acos(sin((".$postLat."*pi()/180)) * sin(('lat'*pi()/180))+cos((".$postLat."*pi()/180)) * cos(('lat'*pi()/180)) * cos(((".$postLon."- 'lng')*pi()/180))))*180/pi())*60*1.1515) as distance
FROM `postcode` WHERE distance = ".$d."");
?>
しかし、非常に多くの例があります!?!?!?!! – Strawberry
@Strawberryあなたは精巧で、おそらく私にこれらの例の1つへのリンクをお願いします。 – JackDaniels
このフォーラムで「haversine」または「経度」を検索してください。または、「緯度経度」タグをクリックします。 –