0

距離(直線)

from: (緯度) 48.73233 (経度) 2.36618

to: lat() 48.84647 (ロング) 2.41026

一部に等しい: 13096.16 メートル

PHP 式を使用すると、適切な結果が得られます。

しかし、同じ PHP 式を MySQL クエリに直接変換すると、5904.2757 などが得られます。

コードは次のとおりです。

php:

$distance = atan2(sqrt(pow(sin((($to_lat - $from_lat) * M_PI / 180) / 2), 2) +
         cos(($from_lat * M_PI / 180)) * cos(($to_lat * M_PI / 180)) *
         pow(sin((($to_long - $from_long) * M_PI / 180) / 2), 2)), sqrt(1 - (pow(sin((($to_lat - $from_lat) * M_PI / 180) / 2) 、 2) +
         cos(($from_lat * M_PI / 180)) * cos(($to_lat * M_PI / 180)) *
         pow(sin((($to_long - $from_long) * M_PI / 180) / 2), 2)))) * 2 * $radiusOfEarth;

mysql:

atan2(sqrt(pow(sin(((ap.Latitude - $from_lat) * pi() / 180) / 2), 2) +
             cos(($from_lat * pi() / 180)) * cos((ap.Latitude * pi() / 180)) *
             pow(sin(((ap.Longitude - $from_long) * pi() / 180) / 2), 2)), sqrt(1 - (pow(sin(((ap.Latitude - $from_lat) * pi()) / 180) / 2), 2) +
             cos(($from_lat * pi() / 180)) * cos((ap.Latitude * pi() / 180)) *
             pow(sin(((ap.Longitude - $from_long) * pi() / 180) / 2), 2)))) * 2 * 距離として 6371000
4

1 に答える 1

1

あなたが望む正確なもの。

SELECT ((ACOS(SIN(48.73233 * PI() / 180) * SIN(48.84647 * PI() / 180) + COS(48.73233 * PI() / 180) *
COS(48.84647 * PI() / 180) * COS((2.36618 - 2.41026) * PI() / 180)) * 180 / PI()) * 60 *1.1515 * 1.609344 *1000)
AS distance FROM dual;
于 2012-10-02T15:02:10.353 に答える