0

緯度と経度を含む foodjoint データを含むテーブルがあります。

このクエリを使用しています

 $q = "SELECT (
              (ACOS(SIN( ".$userLatitude." * PI() / 180) * SIN(foodjoint_latitude * PI() / 180) + COS(".$userLongitude." * PI() / 180) * COS(foodjoint_longitude * PI() / 180) * COS((foodjoint_longitude - ".$longitude.") * PI() / 180)) * 180 / PI()) * 60 * 1.1515 * 1.609344) AS distance
             , foodjoint_id
             , foodjoint_name
             , open_hours
             , cont_no
             , AVG(customer_ratings) AS rating
             , address_line
             , city 

          FROM provider_food_joints,customer_review HAVING distance <=3";

$userLatitude と $userLongitude はユーザーの場所です。距離を km で比較したいです。事前にt​​hnx。半径 3 km 未満の foodjoint データを表示したいと考えています。

実行しただけでは、行は選択されませんが、この条件がなければ、すべてのレコードがフェッチされます。

4

1 に答える 1

0

私のプロジェクトでいくつかのコードを見つけましたが、距離の計算についてはよくわかりません。ただし、改善する必要JOINがあります。テーブルは何に参加していますか?

$q = "SELECT (
                    (
                        (
                            ACOS(
                                SIN(".$userLatitude." * PI() / 180) * 
                                SIN(foodjoint_latitude * PI() / 180) + 

                                COS(".$userLatitude." * PI() / 180) * 
                                COS(foodjoint_latitude * PI() / 180) *
                                COS(
                                    (".$userLongitude." - foodjoint_longitude) * PI() / 180)
                                ) * 
                            180 / PI()
                        ) * 60 * (1.1515*1.609344)
                    ) AS distance

           , foodjoint_id
           , foodjoint_name
           , open_hours
           , cont_no
           , AVG(customer_ratings) AS rating
           , address_line
           , city 

        FROM provider_food_joints,customer_review 
      HAVING distance < 4";
于 2012-05-05T06:45:29.447 に答える