当从纬度和纬度计算数学距离时,距离是NULL值。经度

时间:2016-07-27 13:08:21

标签: php mysql

我有两张桌子:

一个是旅行,另一个是物品......

这是项目表中的元组:

|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
|  id  |  item_desc    |   sending_from_latitude  |   sending_from_longitude   |  sending_to_latitude   |  sending_to_longitude    |   from_date  |  to_date   |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
|  1   |  Toy Gun      |        15.2993265        |      74.12399599999999     |       10.8505159       |         76.2710833       | 2016-07-27   | 2016-07-30 |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------|

现在,这里是旅行表的元组:

|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|  id  |  trip_desc    |   travelling_from_latitude |   travelling_from_longitude   |  travelling_to_latitude   |  travelling_to_longitude  |   from_date  |  to_date   |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|  1   |  Bombay 2 Goa |        15.2993265          |      74.12399599999999        |       10.8505159          |         76.2710833        | 2016-07-27   | 2016-07-30 |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|

我想做什么?

有一个网络应用程序可以从项目获得 sending_from_latitude sending_from_longitude sending_to_latitude sending_to_longitude

然后它将选择所有行程:

  1. travelling_from_latitude将与sending_from_latitude匹配。
  2. travelling_from_longitude将与sending_from_longitude匹配。
  3. travelling_to_latititude将与sending_to_latitude匹配。
  4. travelling_to_longitude将与sending_to_longitude匹配。
  5. 所以我写了一个函数:

    function getTripListMatchingItem($Flat,$Flon,$Tlat,$Tlon,$Weight,$FromDate,$ToDate,$carrier_id,$rad)
        {
            $R = 6371;  //Earth's Mean Radius
            $queryTrip =    "SELECT *, (        6371 *
                                                acos(
                                                    cos( radians( $Flat ) ) *
                                                    cos( radians( `travelling_from_latitude` ) ) *
                                                    cos(
                                                        radians( `travelling_from_longitude` ) - radians( $Flon )
                                                    ) +
                                                    sin(radians($Flat)) *
                                                    sin(radians(`travelling_from_latitude`))
                                                )
                                            ) `fromdistance`, 
                                            (   6371 *
                                                acos(
                                                    cos( radians( $Tlat ) ) *
                                                    cos( radians( `travelling_to_latitude` ) ) *
                                                    cos(
                                                        radians( `travelling_to_longitude` ) - radians( $Tlon )
                                                    ) +
                                                    sin(radians($Tlat)) *
                                                    sin(radians(`travelling_to_latitude`))
                                                )
                                            ) `todistance`
                                    FROM `trips` as Trip
                                    WHERE from_date = '$FromDate' 
                                        AND to_date = '$ToDate' 
                                        AND wait_will_carry = '$Weight'
                                        AND member_id = '$carrier_id'
                                        AND isBooked = '0'
                                        AND isActive = '1'
                                        AND isStatus = '1'
                                        AND isDelete = '0'";
                                    //HAVING (`fromdistance` > $rad AND `todistance` > $rad)
                                    //ORDER BY `fromdistance`";
            echo    $queryTrip;                 
            return $this->query($queryTrip);
        }
    

    我以前称之为: -

    $tripListArray = $this->Trip->getTripListMatchingItem($tripFromLat,$tripFromLong,$tripToLat,$tripToLong,$tripWeight,$tripStartDate,$tripEndDate,$carrier_id,400);
    

    我收到了空白数据。所以我删除了

    的条件
    //HAVING (`fromdistance` > $rad AND `todistance` > $rad)
    //ORDER BY `fromdistance`";
    

    我只检查我得到的todistance值。 我的数据为空的原因是todistance为空。

    如果商品latitude and longitude与行程latitude & longitude准确一致,fromdistance& todistance两者都应为零。

    为什么我将fromdistance作为todistance作为 NULL

    enter image description here

    这是我回应的实际MySQL查询:

    SELECT *, (
            6371 *
            acos(
                cos( radians( 15.2993265 ) ) *
                cos( radians( `travelling_from_latitude` ) ) *
                cos(
                    radians( `travelling_from_longitude` ) - radians( 74.12399599999999 )
                ) +
                sin(radians(15.2993265)) *
                sin(radians(`travelling_from_latitude`))
                )
            ) `fromdistance`, (
                        6371 *
                        acos(
                            cos( radians( 10.8505159 ) ) *
                            cos( radians( `travelling_to_latitude` ) ) *
                            cos(
                                radians( `travelling_to_longitude` ) - radians( 76.2710833 )
                            ) +
                            sin(radians(10.8505159)) *
                            sin(radians(`travelling_to_latitude`))
                        )
                    ) `todistance`
            FROM `trips` as Trip
            WHERE from_date = '2016-07-27' 
            AND to_date = '2016-07-30' 
            AND wait_will_carry = '4'
            AND member_id = '13'
            AND isBooked = '0'
            AND isActive = '1'
            AND isStatus = '1'
            AND isDelete = '0'
    

0 个答案:

没有答案