半径搜索结果在php中运行

时间:2014-03-19 21:00:42

标签: php

我的网站上有一个搜索功能,它接收城市状态和Zip并搜索半径并显示我测试过的所有结果,但它在此编码的这一行中断了:

if ($origin_id[0] != -1)
        $sql .= " AND " . $prefix . ".OriginLocationID IN (" . implode(",", $origin_id) . ") ";

全局定义并正确显示...如果我没有放入半径,它将显示该城市的结果..但是输入半径后它会中断...

我也包括了Radius功能......

function GetLocationSearchCriteria(&$sql, &$urlappend, $prefix)
    {
        $origin_id = Location::GetLocationID($GLOBALS["OriginState"], $GLOBALS["OriginCity"], $GLOBALS["OriginZip"]);

        if (!is_array($origin_id))
        {
            $o = $origin_id;
            $origin_id = array();
            $origin_id[0] = $o;
        }

        if (!empty($GLOBALS["OriginRadius"]))
        {
            $origin = new Location($origin_id[0]);
----------->>>>>>   $origin_id = $origin->GetRadiusLocations($GLOBALS["OriginRadius"]);
            $urlappend .= "&OriginRadius=" . $GLOBALS["OriginRadius"];
        }

        // build query
        if ($origin_id[0] != -1)
            $sql .= " AND " . $prefix . ".OriginLocationID IN (" . implode(",", $origin_id) . ") ";
    }

    function GetRadiusLocations($radius)
        {
            $sql = "SELECT LocationID 
                    FROM locations 
                    WHERE (POW((69.1*(Longitude\"" . $this->Longitude . "\")*" . cos($this->Latitude/57.3) . "),\"2\")+POW((69.1*(Latitude-\"" . $this->Latitude . "\")),\"2\"))<(" . $radius * $radius . ") ";

            $conn = &$GLOBALS["dbSettings"]->GetConnection();
            $rs = &$conn->Execute($sql);
            if ($rs === false)
                return -1;
            $location_ids = array();
            while (!$rs->EOF)
            {
                array_push($location_ids, $rs->fields[0]);
                $rs->MoveNext();
            }
            return $location_ids;
        }

1 个答案:

答案 0 :(得分:0)

找到了解决方案......我错过了 - 在等式中的经度之后......

应该是这个

(POW((69.1 *(经度 - \&#34;&#34;。$ this-&gt;经度。&#34; \&#34;)&#34; .cos($ this-&gt; Latitude / 57.3)。&#34;),\&#34; 2 \&#34;)+ POW((69.1 (纬度 - \&#34;&#34;。$ this-&gt; Latitude。&#34; \&#34;)),\&#34; 2 \&#34;))&lt;(&#34;。$ radius * $ radius。&#34;) &#34 ;;