当前位置:网站首页>Php:redis uses geospatial
Php:redis uses geospatial
2022-06-12 10:20:00 【Qu Shuai 369】
Go straight to the code :
//geoAdd: Will give the space element ( longitude 、 latitude 、 name ) Add to the specified key . The data will be stored in keys in an ordered set , To make it look like GEORADIUS and GEORADIUSBYMEMBER Such a command can later retrieve these elements through a location query
//geoAdd($key, $longitude( longitude ), $latitude( latitude ), $name [, $longitude, $latitude, $member, ...]);
$redis->del("myplaces");
//key Whether the value exists
$redis->exists("myplaces");
// The effective longitude is -180 C to 180 degree
// The effective latitude is -85.05112878 C to 85.05112878 degree ( All data will fail to be added as long as invalid longitude and latitude occur )
$result = $redis->geoAdd('myplaces', '-157.478799', '21.235456', 'Honolulu', '116.404269', '39.91582', 'beijing', '121.47879', '31.235456', 'shanghai');
dump($result);
//geoHash(key,name1,name2,namen) Returns the... Of one or more positional elements Geohash character string Returns one or more elements Geohash Array of strings
$hashes = $redis->geoHash("myplaces", "San Francisco", "Honolulu","beijing","shanghai");//['87z9pyek3y0','8e8y6d5jps0']
dump($hashes);
//geoPos(key,name1,name2,namen): Return all the positions of the positioning elements from the key ( Longitude and latitude ) Command returns an array , Each item in the array consists of two elements ( longitude , latitude ) form
$positions = $redis->geoPos("myplaces", "San Francisco", "Honolulu");//[[37.773, -122.431],[-157.858, 21.315]]
dump($positions);
//GeoDist(key,name1,name2 [, $unit='m']): Returns the distance between two given positions unit contain m、km、mi( miles )、ft( feet )
$kilometers = $redis->geoPos("myplaces", "San Francisco", "Honolulu",'km');//168.2752
dump($kilometers);
//geoRadius($key, $longitudee( longitude ), $latitude( latitude ), $radius( radius ), $unit [, Array $options]): Centered on a given latitude and longitude , Return key contains position elements , The distance from the center shall not exceed the given maximum radius radius All position elements of the distance
dump($redis->geoRadius("myplaces", 123.858, 42.306, 10000, 'km'));
// Express 10000km Extraction of ranges 2 individual
$options['count'] = 2;
//ASC|DESC
$options[] = 'ASC';
//WITHCOORD: It also returns the longitude of the matching item , Latitude coordinates .
$options[] = 'WITHCOORD';
//WITHDIST: Also return to the designated center to return the distance of the item . The distance is returned in the same units as the radius parameter specified for the command .
$options[] = 'WITHDIST';
dump($redis->geoRadius("myplaces", 123.858, 42.306, 10000, 'km', $options));
//geoRadiusByMember($key, $name, $radius, $units [, Array $options]): Function and geoRadius It's just that the origin is name Decide not like geoRadius Enter longitude and latitude to determine
dump($redis->geoRadiusByMember("myplaces", "shanghai", 3000, 'km'));Execution results :
int(3)
array(4) {
[0] => bool(false)
[1] => string(11) "8eb0b3z3w00"
[2] => string(11) "wx4g0f7n800"
[3] => string(11) "wtw3sq4psz0"
}
array(2) {
[0] => array(0) {
}
[1] => array(2) {
[0] => string(22) "-157.47879713773727417"
[1] => string(20) "21.23545663354175161"
}
}
array(3) {
[0] => array(0) {
}
[1] => array(2) {
[0] => string(22) "-157.47879713773727417"
[1] => string(20) "21.23545663354175161"
}
[2] => array(0) {
}
}
array(3) {
[0] => string(8) "shanghai"
[1] => string(7) "beijing"
[2] => string(8) "Honolulu"
}
array(2) {
[0] => array(3) {
[0] => string(7) "beijing"
[1] => string(8) "678.5471"
[2] => array(2) {
[0] => string(21) "116.40426903963088989"
[1] => string(20) "39.91581928642635546"
}
}
[1] => array(3) {
[0] => string(8) "shanghai"
[1] => string(9) "1249.2980"
[2] => array(2) {
[0] => string(21) "121.47878855466842651"
[1] => string(20) "31.23545629441388627"
}
}
}
array(2) {
[0] => string(8) "shanghai"
[1] => string(7) "beijing"
}
array(1) {
[0] => array(0) {
}
}
边栏推荐
- Jetpack architecture component learning (3) -- activity results API usage
- postgresql 使用存储过程,拼接多张表,查询数据
- JVM (III) Virtual machine performance monitoring & fault handling tool
- MYSQL的最左匹配原则的原理讲解
- QT custom window fillets
- VSCode代码调试技巧
- 93. 获得内网的所有IP地址
- CentOS 7 installing MySQL 8
- SAP Hana error message sys_ XSA authentication failed SQLSTATE - 28000
- Implementation principle of redisson distributed lock
猜你喜欢
![[Wayland] Weston multi screen display](/img/58/698e2cc790d3dbef9260cb2ad690d8.jpg)
[Wayland] Weston multi screen display

tp6调试(trace)

性能指标的信仰危机

Explication du principe d'appariement le plus à gauche de MySQL

极速搭建元宇宙画廊 #oncyber.io

MYSQL的最左匹配原則的原理講解

Create simple windowing programs using Visual Studio 2017

Circuitbreaker fuse of resilience4j -- Measurement of circuitbreakermetrics index

原始套接字使用

Strange error -- frame detected by contour detection, expansion corrosion, and reversal of opening and closing operation effect
随机推荐
Circuitbreaker fuse of resilience4j - circuitbreakerevent event
FPGA基于DE2-115平台的VGA显示
High performance computing framework for image processing
93. obtain all IP addresses of the Intranet
Docker compose integrates redis, MySQL and microservices, and services are containerized
MYSQL的最左匹配原則的原理講解
Implementation principle of redisson distributed lock
2021-03-26
Strange error -- frame detected by contour detection, expansion corrosion, and reversal of opening and closing operation effect
Win10 professional edition user name modification
VSCode代码调试技巧
93. 获得内网的所有IP地址
Checkpoint of the four cornerstones of Flink
C break continue return
3. Abstract Factory
Student management system
conda 安装tensorflow 测试tensorflow
OpenCV中CLAHE用于16位图像增强显示
【926. 将字符串翻转到单调递增】
postgresql 使用存储过程,拼接多张表,查询数据