does not show proper foodjoint data under 3 km radious

I have a table containing foodjoint data with their latitude and longitude.

I am using this query

 $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 and $userLongitude is the users location.I want the distance to be compared in km. thnx in advance. I want to display the foodjoint data under 3 km radious.

when I just running it doesn't select any row.but with out this having condition it fetches all the records.

Answers


I found some code in a project of mine, but i'm not sure about the distance calculation.. You should improve your JOIN though.. What are the tables joining on?

$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";

Need Your Help

How should I check if a .NET decimal value is a whole number?

.net vb.net decimal

I have class representing a unit of measure with a Decimal as the numeric. Just to simplify things for this example, let's say I'm representing centimeters. I'd like to implement a ToString() met...