Рубрики
Uncategorized

Используйте redis-geo API для поиска людей поблизости и самостоятельно напишите пакет composer

Автор оригинала: David Wong.

Адрес Git

Вам нужно использовать composer , установить composer, китайское зеркало composer

Если он применяется к проекту, найдите корневой каталог и composer.json Того же уровня

composer require gaopengfei/redis_lbs

Инициализация

require_once __DIR__.'/vendor/autoload.php';
$lbs = new \LBS\Services\LBSService();

Добавить к

$add_params = [
    [
        'name' => 'yabao_road',
        'long' => '116.43620200729366',
        'lat' => '39.916880160714435'
    ],
    [
        'name' => 'jianguomen',
        'long' => '116.4356870231628',
        'lat' => '39.908560377800676'
    ],
    [
        'name' => 'chaoyangmen',
        'long' => '116.4345336732864',
        'lat' => '39.924466658329585'
    ],
    [
        'name' => 'galaxy_soho',
        'long' => '116.4335788068771',
        'lat' => '39.921372916981106'
    ],
    [
        'name' => 'cofco',
        'long' => '116.43564410781856',
        'lat' => '39.92024564137184'
    ],
    [
        'name' => 'fesco',
        'long' => '116.435182767868',
        'lat' => '39.91811857809279'
    ],


];
/**
 * Add a new coordinate to the set
 * @param array $params
 * Structures are ['name'=>'xxx','long'=>'1.2321','lat'=>'1.3112'] or [['name'=>'xxx','long'=>'1.2321','lat'=>'1.3112']]
 * @param null $key
 * @return int
 */
$res = $lbs->add($add_params);

Return
int 6

удалить

/**
 * Delete specified elements in a collection
 * @param $name
 *@ Param null $key defaults to a collection, which can be specified
 * @return int
 */
$res = $lbs->del('gao1');

Return
Int 0 or 1


If the collection name is specified
$res = $lbs->del('gao1','set-name');

Используйте координаты для запроса близлежащих объектов

/**
 * Query range elements, if you do not change the key, use the default
 *@ Param $long longitude
 *@ Param $lat latitude
 *@ Param $radius range
 *@ Param $unit (m, km, ft, mi only)
 *@ Param null $key collection name
 * @return mixed
 */
$search = $lbs->search('116.435182767868','39.91811857809279',500,'m');

Return array
array:4 [▼
  0 => array:2 [▼
    "name" => "fesco"
    "dist" => "0.1250"
  ]
  1 => array:2 [▼
    "name" => "yabao_road"
    "dist" => "162.8454"
  ]
  2 => array:2 [▼
    "name" => "cofco"
    "dist" => "239.7758"
  ]
  3 => array:2 [▼
    "name" => "galaxy_soho"
    "dist" => "386.9165"
  ]
]

Запрос на основе существующего местоположения

/**
 * Query the range elements according to the elements in the collection, and use the default if you don't change the key
 *@ Element names in the set of param $name
 *@ Param $radius range
 *@ Param $unit
 *@ Param null $key collection name
 * @return mixed
 */
$search = $lbs->->searchByMembers('fesco',500,'m');

Return array
array:4 [▼
  0 => array:2 [▼
    "name" => "fesco"
    "dist" => "0.1250"
  ]
  1 => array:2 [▼
    "name" => "yabao_road"
    "dist" => "162.8454"
  ]
  2 => array:2 [▼
    "name" => "cofco"
    "dist" => "239.7758"
  ]
  3 => array:2 [▼
    "name" => "galaxy_soho"
    "dist" => "386.9165"
  ]
]

Перечислите все значения коллекции (фактически, диапазон)

/**
 * List the contents of the collection
 *@ The key of the set of param $key
 *@ Param int $start starting position
 *@ Param int $end end end position - 1 until end
 * @return array
 */
$list = $lbs->list($test->geoset_name,2,-1);

Return array
array:6 [▼
  0 => "jianguomen"
  1 => "yabao_road"
  2 => "fesco"
  3 => "cofco"
  4 => "galaxy_soho"
  5 => "chaoyangmen"
]

Оригинал блога