データベースには、緯度と経度とともに保存する会場があります。
ログインしているユーザーの緯度と経度も持っています。
私は、20マイルなど、特定の測定範囲内で会場を見つけることができる機能を開発しています.
ユーザーの緯度と経度から20マイルの最も外側の緯度と経度を見つけて、MySQLの距離の円内にある場所を見つけるためのクエリを何らかの形で書くことは可能ですか?
ありがとう。
私はこれを使用します(javascriptからObjective-Cに移植)-javascriptで表現された多くの優れた位置方程式http://www.movable-type.co.uk/scripts/latlong.html
動作する PHP 関数を見つけました。
function getDistanceBetweenPoints($latitude1, $longitude1, $latitude2, $longitude2, $unit = 'Mi') {
$theta = $longitude1 - $longitude2;
$distance = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)));
$distance = acos($distance);
$distance = rad2deg($distance);
$distance = $distance * 60 * 1.1515; switch($unit) {
case 'Mi': break; case 'Km' : $distance = $distance * 1.609344;
}
return (round($distance,2));
}
これは他の人を助けるかもしれないと思った。