0

以下のコードは次の場所にあります: /includes/search/functions/ajax.php 行: 1489

これは、選択した検索フィールドに基づいて、特定のページのマップにピンを設定するものです...

マップ上のすべてのピンが読み込まれないように、この検索を特定の半径に制限する方法を誰かが教えてくれますか?

今のところ、すべてのピンがマップに読み込まれており、割り当てられた CPU 電力を消費しており、1000 を超えるピンがすぐに読み込まれると最終的にブラウザがクラッシュする可能性があります。

/////////////////////////////////////////////////////////////////
            //// ACTUALLY DOES THE QUERY
            /////////////////////////////////////////////////////////////////

            $sQ = new WP_Query($args);

            //// STARTS OUR POST ARRAY - EVERY FOUND POST IS INSERTED IN HERE IN ORDER TO ADD THE PINS
            $return['posts'] = array();
            $return['post_ids'] = array();

            /// LOOPS POSTS
            if($sQ->have_posts()) { while($sQ->have_posts()) { $sQ->the_post();

                ///// GETS REQUIRED FIELDS TO INSERT IN THE ARRAY
                $latitude = get_spot_latitude(get_the_ID());
                $longitude = get_spot_longitude(get_the_ID());
                $pin = get_spot_pin(get_the_ID());

                $featured = 'false';
                $thumb = '';

                //// IF FEATURED OVERLAYS ARE SET
                if(ddp('map_featured_overlay') == 'on') {

                    //// IF THIS IS FEATURED
                    if(get_post_meta(get_the_ID(), 'featured', true) == 'on') { $featured = 'true'; }
                    $thumb = ddTimthumb(btoa_get_featured_image(get_the_ID()), 150, 150);

                }

                //// ONLY ADDS TO THE ARRAY IN CASE WE HAVE A LATITUDE AND LONGITUDE
                if($latitude != '' && $longitude != '') {

                    $return['posts'][] = array(

                        'title' => get_the_title(),
                        'id' => get_the_ID(),
                        'latitude' => $latitude,
                        'longitude' => $longitude,
                        'pin' => $pin,
                        'permalink' => get_permalink(),
                        'featured' => $featured,
                        'thumb' => $thumb,

                    );

                    $return['post_ids'][] = get_the_ID();

                } else {

                    $return['posts'][] = array(

                        'title' => get_the_title(),
                        'error' => 'NO LATITUDE OR LONGITUDE'

                    );

                }//// ENDS IF POST HAS LATITUDE AND LONGITUDE

            } }

これは検索フィールドの一部です:

<input type="hidden" id="_sf_enable_radius_search" value="false" name="_sf_enable_radius_search" />
                    <input type="hidden" id="_sf_radius_lat_from" value="" name="_sf_radius_lat_from" />
                   <input type="hidden" id="_sf_radius_lat_to" value="" name="_sf_radius_lat_to" />
                       <input type="hidden" id="_sf_radius_lng_from" value="" name="_sf_radius_lng_from" />
                   <input type="hidden" id="_sf_radius_lng_to" value="" name="_sf_radius_lng_to" />
                       <input type="hidden" id="_sf_radius_center_lat" value="" name="_sf_radius_center_lat" />
                       <input type="hidden" id="_sf_radius_center_lng" value="" name="_sf_radius_center_lng" />
                       <input type="hidden" id="_sf_radius_field" value="false" name="_sf_radius_field" />
                    <input type="hidden" id="_sf_radius_field_id" value="false" name="_sf_radius_field_id" />
                      <input type="hidden" id="_sf_post_ids" value="" name="_sf_post_ids" />


                       <input type="hidden" id="_sf_radius_distance" value="" name="_sf_radius_distance" />

                        <input type="hidden" name="is_taxonomy" value="true" id="_sf_search_is_taxonomy" />
4

2 に答える 2

0

ある緯度/経度の位置から別の位置までの距離を計算する必要があります。この距離が計算されたら、それを最大半径と比較できます。これを行う 1 つのアルゴリズムは、Haversine 式です。

インターネット上でこれの多くの実装を見つけることができます。これは PHP のものです。

function getDistance($latFrom, $longFrom, $latTo, $longTo)
{
    $dLat = deg2rad($latTo - $latFrom);
    $dLon = deg2rad($longTo - $longFrom);

    $angle = sin($dLat / 2) * sin($dLat / 2) + cos(deg2rad($latFrom)) * cos(deg2rad($latTo)) * sin($dLon / 2) * sin($dLon / 2);

    $c     = 2 * asin(sqrt($angle));

    $distance = 6371000 * $c;

    // Distance is in metres
    return $distance;
}

(上記のスニペットは基本的に同じです)を参照してください:PHPのみを使用して、特定の座標が別の座標半径に収まるかどうかを確認する方法

中心の緯度/経度と記録の緯度/経度を渡して距離をメートル単位で取得し、比較します。

if (getDistance(0, 0, 0, 0) < 1000) {
    // do stuff
}

1000あなたの半径はどこですか。

于 2014-03-04T21:47:38.863 に答える