With the increasing number of location information services (LBS) in daily life. For example, the logistics platform industry in which the author works, the rapidly developing Pupu Life supermarket in Fuzhou, as well as take-out and taxi hailing, cannot do without GEO technology.
First, let’s analyze the requirements of LBS:
- Supports the preservation of latitude and longitude of an object
- Supports matching of points near points
- Query object information based on the object ID
The Hash type in Redis can well support access to the corresponding location of the key, such as the vehicle location
However, the Hash element is out of order and does not satisfy the range query.
When we think about Sorted, we naturally think about Sorted Set. As follows:
The Sorted Set element weight score needs to be a number (which can be a floating point number). The latitude and longitude are two values, which cannot be directly saved as a floating point number.
As a result, we need to use the GeoHash encoding to do the transformation. GeoHash encoding can be summed up in just eight words: binary interval, interval encoding
First we imagine the map as a square divided into four parts, as shown in the figureSo you can map theta to a one-dimensional space. Each square can be further divided, the finer the division, the smaller the corresponding geographical space, the greater the accuracy.
www.redis.com.cn/redis-geo.h… Redis provides the six commands required by GEO
Appendix :GeoHash coding site geohash.org/