Target location user query method, device, equipment and storage medium

The S2 grid coverage algorithm converts the target area range into a multi-section one-dimensional value interval, solving the problem of inefficient search efficiency under dynamic update of massive user locations in LBS, and achieving efficient and real-time target user query.

CN116776010BActive Publication Date: 2025-08-26CHINA MOBILE (SUZHOU) SOFTWARE TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310007475.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-01-04
Publication Date
2025-08-26
Estimated Expiration
2043-01-04

AI Technical Summary

Technical Problem

In LBS, the existing technology is inefficient in how to efficiently find users within the target area under dynamic updates of massive user locations, especially the level traversal efficiency of Google S2 grid-coded Level-15 and Level-22, and the K-V structure cannot incrementally update user locations.

Method used

The S2 grid coverage algorithm is used to convert the target area range into a multi-section one-dimensional value interval, and the user identification and position encoding are stored in the grid database by using S2 grid encoding. The candidate user set is found through the one-dimensional value interval, and the target users are filtered out within the target area range.

Benefits of technology

It realizes efficient search of users in the target area among a large number of users, improves processing efficiency, supports interval value search in any query area, and allows incremental updates and instant feedback of user locations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116776010B_ABST
    Figure CN116776010B_ABST
Patent Text Reader

Abstract

The embodiments of the present application disclose a method, apparatus, device, and storage medium for querying users at a target location, wherein the query method includes: obtaining the target area range to be queried; converting the target area range into a multi-segment one-dimensional value interval through the S2 grid coverage algorithm; searching for a candidate user set whose position codes satisfy the multi-segment one-dimensional value interval from a preset grid database; the grid database stores multiple user identifiers and the position codes associated with each of the users; and screening the candidate user set using the target area range to determine the target user within the target area range. By uniformly encoding the user positions and converting the target area range into a multi-segment one-dimensional value interval, there is no need to adjust the user position storage logic according to different query areas, and a one-dimensional search for interval values ​​can be performed for any query area, greatly improving processing efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to, but is not limited to, the field of big data processing technology, and in particular to a method, apparatus, device, and storage medium for querying users at a target location. Background Art

[0002] Location-based services (LBS) typically require the system to process the locations of a large number of users, and these locations are constantly updated. Finding a target user based on a location range is a common requirement. However, due to the variability of user locations and the uncertainty of the area range, efficiently retrieving the target results for such a large user base becomes a daunting challenge. Carriers' location signaling big data faces this challenge.

[0003] Existing Google S2 grid encoding technology for range search has the following shortcomings: It uses Level-15 and Level-22 traversals, which is inefficient when the number of grids is large; the KV structure, which uses time + grid as the key and user sets as the value, cannot incrementally update user locations, and all user locations must be fully recorded in each time slice. Summary of the Invention

[0004] In view of this, the embodiments of the present application provide a method, apparatus, device and storage medium for querying users in a target location, which at least solves the problem of inefficiency in searching for users within a target area among a large number of users due to changes in user locations and uncertainty in area scope.

[0005] The technical solution of the embodiment of the present application is implemented as follows:

[0006] In a first aspect, an embodiment of the present application provides a method for querying a user at a target location, the method comprising:

[0007] Obtain a target area range to be queried; convert the target area range into a multi-segment one-dimensional value interval through an S2 grid coverage algorithm; search a preset grid database for a set of candidate users whose position codes satisfy the multi-segment one-dimensional value interval; the grid database stores identifiers of multiple users and position codes associated with each of the users; use the target area range to screen the candidate user set and determine the target users within the target area range.

[0008] In some embodiments, converting the range of the target area into multiple one-dimensional value intervals through the S2 grid coverage algorithm includes: using the S2 grid coverage algorithm to determine the N grids covered by the target area; wherein N is less than or equal to a preset maximum number of grids, and the level of each of the grids is between a preset minimum level and a maximum level; converting the S2 grid code of each of the grids into a one-dimensional value interval; connecting the value intervals of adjacent grids in the N grids end to end to obtain a merged M one-dimensional value interval; wherein M is a natural number less than N.

[0009] In some embodiments, the method further includes: encoding the two-dimensional coordinates of each user using the S2 geographic location coding system to obtain the location code of the corresponding user; using the identifier of each user as a key and the location code of the corresponding user as a value to store in the grid database.

[0010] In some embodiments, the position code is a first-level grid precision, the grid database is an ordered set structure of Redis, and the value of the ordered set structure is a double-precision floating point type. The method further includes: for each of the users, converting the position code of the first-level grid precision into a position code of the second-level grid precision matching the double-precision floating point type; storing the position code of the second-level grid precision as a value associated with the corresponding user in the ordered set structure; wherein the grid corresponding to the second-level grid precision is the parent grid of the grid corresponding to the first-level grid precision.

[0011] In some embodiments, the method further includes: in response to the update of the two-dimensional coordinates of the first user, encoding the updated two-dimensional coordinates to obtain a new position code; and updating the value associated with the first user in the grid database using the new position code.

[0012] In some embodiments, searching from a set grid database for a set of candidate users whose position codes satisfy the multiple one-dimensional value intervals includes: for each one-dimensional value interval, searching from the grid database for users whose position codes belong to the corresponding one-dimensional value interval to obtain a query result; the query result includes the user's identifier and the associated position code; and merging the query results of the multiple one-dimensional value intervals to obtain the candidate user set.

[0013] In some embodiments, the using the target area range to screen the candidate user set and determine the target user within the target area range includes: for each candidate user in the candidate user set, if the boundary of the target area range completely contains the minimum grid to which the location of the corresponding candidate user belongs, determining the corresponding candidate user as the target user.

[0014] In a second aspect, an embodiment of the present application provides a device for querying a user at a target location, the device comprising:

[0015] The acquisition module is used to obtain the target area range to be queried;

[0016] A conversion module, configured to convert the target area range into multiple one-dimensional value intervals through an S2 grid covering algorithm;

[0017] A search module is used to search for a set of candidate users whose position codes satisfy the multiple one-dimensional value intervals from a preset grid database; the grid database stores multiple user identifiers and position codes associated with each of the users;

[0018] The screening module is configured to screen the candidate user set using the target area range to determine target users within the target area range.

[0019] In a third aspect, an embodiment of the present application provides a computer device comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the processor executes the program, some or all of the steps in the above method are implemented.

[0020] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, which implements some or all of the steps in the above method when executed by a processor.

[0021] The embodiments of the present application have at least the following technical effects:

[0022] In the embodiment of the present application, the S2 grid coverage algorithm is used to process the target area to be queried into multiple one-dimensional value intervals under the grid. At the same time, the user's identity and location code are associated and stored in the grid database. This allows for a one-dimensional range search of the user's location using the multiple value intervals, obtaining the user's location under the regional coverage grid, and then screening out the target user within the target area. In this way, by uniformly encoding the user's location and converting the target area into multiple one-dimensional value intervals, there is no need to adjust the user location storage logic according to different query areas. One-dimensional searches of interval values ​​can be performed for any query area, greatly improving processing efficiency.

[0023] It should be understood that the above general description and the following detailed description are merely exemplary and explanatory, and are not intended to limit the technical solutions of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] The drawings herein are incorporated into and constitute a part of the specification. These drawings illustrate embodiments consistent with the present application and, together with the specification, are used to illustrate the technical solutions of the present application.

[0025] Figure 1 A flowchart of a method for querying a user at a target location provided by an embodiment of the present application;

[0026] Figure 2 A flowchart of a method for querying a user at a target location provided by an embodiment of the present application;

[0027] Figure 3 A flowchart of a method for querying a user at a target location provided by an embodiment of the present application;

[0028] Figure 4 A system framework diagram for searching for target users by location based on regional scope provided in an embodiment of the present application;

[0029] Figure 5A A schematic diagram of a grid coverage graphical effect provided in an embodiment of the present application;

[0030] Figure 5B A schematic diagram of a grid coverage graphical effect provided in an embodiment of the present application;

[0031] Figure 5C A schematic diagram of a grid coverage graphical effect provided in an embodiment of the present application;

[0032] Figure 5D A schematic diagram of a grid coverage graphical effect provided in an embodiment of the present application;

[0033] Figure 6 A schematic diagram of the structure of a query device for a target location user provided in an embodiment of the present application;

[0034] Figure 7 A hardware entity diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0035] In order to make the purpose, technical solutions and advantages of this application clearer, the technical solutions of this application are further elaborated in detail below with reference to the accompanying drawings and embodiments. The described embodiments should not be regarded as limiting this application. All other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0036] In the following description, reference is made to “some embodiments”, which describes a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.

[0037] The terms "first / second / third" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It is understandable that "first / second / third" can be interchanged with a specific order or sequence where permitted so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.

[0038] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this application pertains. The terms used herein are for the purpose of describing this application only and are not intended to limit this application.

[0039] Before further describing the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are first described. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.

[0040] A related technology mentions a grid-based processing method that dynamically adjusts the GeoHash grid size based on the density of registered users, associates users with grids, and selects users with consistent grids as nearby target users. However, using GeoHash grid coding for range searches has the following drawbacks: 1) The grid accuracy must be determined in advance based on various dimensional parameters, and the surrounding grids must be traversed during calculation to achieve searches within a certain range; 2) It is only suitable for searching for similar elements within a certain range from a seed location, such as the "Nearby People" function, and cannot perform range searches on areas with arbitrary boundaries; 3) When the number of users is large and widely distributed, the number of grids and the number of people within each grid are both large, making traversing the grids and then the users within the grids inefficient.

[0041] Another related technique uses S2 to encode locations and build an index for area queries. This method constructs a key-value (KV) structure, where the key uses time + Level-15 grid + Level-22 grid as the index. Using the S2 area coverage algorithm, the resulting coverage grid is matched against the Level-15 and Level-25 secondary indexes, respectively, to retrieve the trajectory data within the corresponding grid. However, this technique for range searches using Google S2 grid encoding has the following drawbacks: 1) It uses fixed levels of Level-15 (306-meter accuracy) and Level-22 (2-meter accuracy) as secondary indexes, requiring all users and regions to be processed sequentially at these two levels. 2) It fails to utilize the S2 encoding property of having similar values ​​in adjacent spaces, instead using a two-level traversal of Level-15 and Level-22, which is inefficient when the number of grids is large. 3) The KV structure, which uses time + grid as the key and user sets as the value, cannot incrementally update user locations; all user locations must be fully recorded for each time slice.

[0042] The present invention provides a method for querying users at a target location, which can be executed by a processor of a computer device. The computer device may include a server, a laptop, a tablet computer, a desktop computer, a smart TV, a set-top box, a mobile device (e.g., a mobile phone, a portable video player, a personal digital assistant, a dedicated messaging device, a portable gaming device), or other device capable of querying users at a target location. Figure 1 A flowchart of a method for querying a user at a target location provided by an embodiment of the present application is shown in FIG. Figure 1 As shown, the method includes the following steps S110 to S140:

[0043] Step S110: Obtain the target area range to be queried.

[0044] Here, the embodiment of the present application aims to query the user data contained in a target area range, i.e., a geographic spatial area, by allowing the user to specify a query condition. The most common way to describe any geographical area range is with a polygon. In particular, a circle can also be approximated with a polygon.

[0045] Step S120: convert the target area range into multiple one-dimensional value intervals through the S2 grid covering algorithm.

[0046] Here, in the implementation, the input target area range is modeled as S2Polygon, and multiple grids of different sizes covered by S2Polygon are obtained according to the regional optimal coverage method (S2RegionCover) provided by S2. Then, the value interval of S2 code under each grid is processed to obtain multiple one-dimensional value intervals.

[0047] It should be noted that Google S2 achieves a dimensionality-reduced representation of the Earth's surface space based on space-filling curves. Google S2's grid accuracy is divided into 30 levels, and a lower-level (larger) grid always covers exactly four higher-level (smaller) grids. All grids are represented using 64-bit fixed-length integers. A grid has a fixed range of values, called the minimum range to maximum range (rangeMin to rangeMax). This range does not overlap with other grids of the same level, and the value range of the parent grid is exactly the same as the union of the value ranges of the subgrids it covers.

[0048] Step S130 : searching a preset grid database for a set of candidate users whose location codes satisfy the multiple one-dimensional value intervals.

[0049] Here, the grid database stores multiple user identifiers and the location codes associated with each user. That is, the grid database has a KV (key-value mapping) structure and supports searches based on value ranges, returning matching key-value pairs, i.e., users and their location codes whose location codes fall within a specified range.

[0050] In practice, each user's location, such as longitude and latitude, is pre-encoded using S2 encoding. This yields a one-dimensional location code for each user and stores it in a grid database with a KV structure, where the key is the user's unique identifier and the value is the corresponding location code, i.e., the highest-precision one-dimensional representation of S2. This facilitates subsequent one-dimensional linear searches based on the region's value range.

[0051] Step S140 : screening the candidate user set using the target area range to determine target users within the target area range.

[0052] Here, since the grid coverage is larger than the actual target area, each user in the candidate user set found by the grid is screened to determine whether the location of the user found by the grid is within the target area, and then the users included in the target area are retained as target users.

[0053] In the embodiment of the present application, the S2 grid coverage algorithm is used to process the target area to be queried into multiple one-dimensional value intervals within the grid. The user's identifier and location code are then stored in a grid database in association with each other. This allows for a one-dimensional range search of the user's location using the multiple value intervals, obtaining the user's location within the regional coverage grid and subsequently screening out the target user within the target area. In this way, by uniformly encoding the user's location and converting the target area into multiple one-dimensional value intervals, there is no need to adjust the user location storage logic based on the query area. One-dimensional searches of interval values ​​can be performed for any query area, greatly improving processing efficiency.

[0054] In some embodiments, before step S130, the method further includes steps 101 and 102:

[0055] Step 101, using the S2 geographic location coding system to encode the two-dimensional coordinates of each user to obtain the location code of the corresponding user;

[0056] Here, each user's two-dimensional coordinates are location coordinates consisting of latitude and longitude. For example, the location coordinates of user u1 are (31.36529787524528, 120.43801146916059). Using the Google S2 geolocation encoding system, these coordinates are converted to an S2 grid code, resulting in a 64-bit integer encoding value, such as 3869610778954949709 (corresponding to the hexadecimal encoding of 35b39e805aa1e44d). According to the S2 encoding rules, this is a Level-30 grid, which has a positioning accuracy of approximately 9 millimeters on the Earth's surface. This means that the encoding accuracy of this user's location is 9 mm.

[0057] Step 102: The identifier of each user is used as a key, and the location of the corresponding user is encoded as a value and stored in the grid database.

[0058] Here, each user corresponds to a unique key, and the user's location can be updated in real time, achieving incremental updates and facilitating instant feedback queries.

[0059] In some embodiments, the position code is a first-level grid precision, the grid database is an ordered set structure of Redis, and the value of the ordered set structure is a double-precision floating point type. The method further includes: for each of the users, converting the position code of the first-level grid precision into a position code of the second-level grid precision matching the double-precision floating point type; storing the position code of the second-level grid precision as a value associated with the corresponding user in the ordered set structure; wherein the grid corresponding to the second-level grid precision is the parent grid of the grid corresponding to the first-level grid precision.

[0060] Here, according to the S2 encoding rules, the first-level grid accuracy is the positioning accuracy corresponding to the Level-30 grid, that is, 9mm, and the second-level grid accuracy is the positioning accuracy corresponding to the Level-25 grid, that is, 30 centimeters (cm). The KVs of the Redis ordered set structure (Sorted Set) are respectively called members and scores. Because its score part is designed as a double-precision floating-point type (double), when using it to store 8-byte integers, only 52 (mantissa) + 1 (sign bit) + 1 (highest bit hidden) = 54 bits of valid bits can be retained. Therefore, according to the S2 encoding rules, the user's unique identifier is used as a member, and the user's Level-25 S2 code is used as the score, which is stored in the user set structure.

[0061] In some embodiments, after step 102, the method further includes: in response to the update of the two-dimensional coordinates of the first user, encoding the updated two-dimensional coordinates to obtain a new position code; and using the new position code to update the value associated with the first user in the grid database.

[0062] In the above embodiment, when the user's location is updated, the longitude and latitude coordinates of the new location are converted into a location code, and the value associated with the user in the KV structure is updated. In this way, the user's location is incrementally updated among a large number of users, allowing for rapid and real-time targeting.

[0063] based on Figure 1 , Figure 2 A flowchart of a method for querying a user at a target location provided by an embodiment of the present application is shown in FIG. Figure 2 As shown, the above step S120 "converting the target area range into multiple one-dimensional value intervals through the S2 grid covering algorithm" includes the following steps S210 to S230:

[0064] Step S210: Determine N grids covered by the target area using the S2 grid coverage algorithm.

[0065] Here, N is less than or equal to the preset maximum number of grids, and the level of each grid is between the preset minimum level and the maximum level; the grid accuracy of Google S2 is divided into 30 levels, and a lower-level (larger) grid can always cover exactly 4 higher-level (smaller) grids.

[0066] Step S220: convert the S2 grid code of each grid into a one-dimensional value interval.

[0067] Here, all grids are represented by 64-bit fixed-length integers. A grid has a fixed value range, called rangeMin~rangeMax, which is the value range of the S2 code under the grid.

[0068] Step S230 , connecting the value intervals of adjacent grids in the N grids end to end to obtain M merged one-dimensional value intervals.

[0069] Here, M is a natural number less than N, for example, N is 8 and M is 6. The merged M segments of the one-dimensional value range contain the same valid values ​​as the original N value ranges. In combination with the characteristics of S2 encoding, the two endpoints of the value range (i.e., rangeMin and rangeMax) are both 30-level encoded, and the last (rightmost) bit is fixed to 1. Therefore, the range of the above values ​​can be extended by two invalid values, rangeMin-1 and rangeMax+1. This optimization connects the value ranges of adjacent grids end to end, thereby reducing the number of segments and facilitating subsequent segmented retrieval queries.

[0070] Figure 3 A flowchart of a method for querying a user at a target location provided by an embodiment of the present application is shown in FIG. Figure 3 As shown, the method includes the following steps S310 to S350:

[0071] Step S310: Obtain the target area range to be queried.

[0072] Step S320: convert the target area range into multiple one-dimensional value intervals through the S2 grid covering algorithm.

[0073] Here, the above steps S310 to S320 correspond to the above steps S110 to S120 respectively, and when implementing, reference may be made to the specific implementation of the above steps S110 to S120.

[0074] Step S330 : for each one-dimensional value interval, searching the grid database for users whose location codes fall within the corresponding one-dimensional value interval to obtain a query result.

[0075] Here, the query result includes the user's identifier and the associated location code.

[0076] Step S340 : merging the query results of the multiple one-dimensional value intervals to obtain the candidate user set.

[0077] For example, user A and A's actual coding position L1 are found, and user B and A's actual coding position L2 are found, and user C and C's actual coding position L3 are found, so that the candidate user set under the regional coverage grid is {user A, user B, user C}.

[0078] Step S350 : for each candidate user in the candidate user set, if the boundary of the target area completely includes the minimum grid to which the location of the corresponding candidate user belongs, determine the corresponding candidate user as a target user.

[0079] Here, the minimum grid is a Level-30 grid with an accuracy of 9 mm. That is, when the minimum grid corresponding to the user position is within the boundary of the target area, it is determined that the user position is indeed within the target area.

[0080] In the above embodiment, the target area range is processed into multiple value intervals, and then the location codes that meet the conditions of the multiple value intervals are searched from the stored grid database to obtain users under the regional coverage grid; at the same time, for each user in the candidate user set screened out by the grid, it is determined whether the target area range includes the minimum grid to which the user's location belongs, so that the target users within the target area range are retained as the final query results.

[0081] The query method for the target location user is described below with reference to a specific embodiment. However, it should be noted that this specific embodiment is only for better illustrating the present application and does not constitute an improper limitation on the present application.

[0082] The embodiment of the present application proposes a system for searching for target users by location based on area range, such as Figure 4 As shown, the system includes a user location storage module 41, an area range processing module 42, a range search user module 43, and a location area matching module 44.

[0083] The user location storage module 41 uses Google's S2 geolocation encoding system to convert the location coordinates of all users into S2 grid codes. The module then stores these codes in a database, using the user's unique identifier as the key and the highest-precision one-dimensional location code within the S2 grid code as the value. Compared to related art techniques that use time_c15_c22 as the key and the set of users at the same grid location as the value, this embodiment encodes the user location, using the user's unique identifier as the key and the highest-precision one-dimensional representation of the S2 grid code as the value.

[0084] Each user's location is represented as latitude and longitude, a two-dimensional coordinate system consisting of latitude and longitude. For example, the location coordinates of user u1 are (31.36529787524528, 120.43801146916059). Using the Google S2 geolocation encoding system, these coordinates are converted to S2 grid codes to obtain a 64-bit integer value, such as 3869610778954949709 (corresponding to the hexadecimal encoding of 35b39e805aa1e44d). This process is coded using the Java SDK as follows:

[0085] 1.S2CellId s2CellId=S2CellId.fromLatLng(

[0086] S2LatLng.fromDegrees(31.36529787524528,120.43801146916059)); 2.System.out.println(s2CellId.id());

[0087] According to the S2 encoding rule, this is the Level-30 grid, which has a positioning accuracy of approximately 9mm on the Earth's surface. All user coordinates are converted in this way. For example, the data for 10 users is shown in Table 1:

[0088] Table 1 The latitude and longitude coordinates of 10 users and their corresponding location codes

[0089] user Latitude and longitude coordinates Positional encoding u1 (31.36529787524528,120.43801146916059) 3869610778954949709 u2 (31.36632390057698,120.43966370991376) 3869610782012042381 u3 (31.365920820532406,120.4422815459123) 3869610806528482041 u4 (31.365462772928936,120.44468480518964) 3869610804782716089 u5 (31.36498640105347,120.44341880253461) 3869610807034091899 u6 (31.364583315273084,120.4407151358476) 3869610780744343071 u7 (31.364528348896393,120.43917018345502) 3869610781522426437 u8 (31.363593915574565,120.43837624958661) 3869610779558776805 u9 (31.363685527095264,120.44052201679852) 3869610780586528131 u10 (31.36265947296363,120.43936330250409) 3869610769638744613

[0090] Select a database with the following characteristics to store users and their location codes: On the one hand, it has a key-value mapping structure, that is, the user is used as the key, each user corresponds to a unique key, and the location code is used as the value to associate with the user; on the other hand, it supports searching by value range and returns key-value pair records that meet the conditions, that is, returns users and their location codes whose location codes are within the specified range.

[0091] A known database that meets the above conditions is implemented as a Redis sorted set, whose key-value pairs are called member and score. Because the score is designed as a double (double-precision floating-point type), when used to store an 8-byte integer, only 52 (mantissa) + 1 (sign bit) + 1 (highest bit hidden) = 54 bits of valid bits can be retained. According to the S2 encoding rule, using 54 bits for Level-25 requires reducing the precision of the level 30 grid and converting it to its level 25 parent grid. For example, the level 25 parent grid of the level 30 grid 3869610778954949709 is encoded as 3869613036593792000 (corresponding to the hexadecimal encoding of 35b3a08e0064c400). This process uses the Java SDK encoding as follows:

[0092] 1.S2CellId pCellId=s2CellId.parent(25);

[0093] 2.System.out.println(pCellId.id());

[0094] According to the S2 encoding rules, this is a Level-25 grid, with a positioning accuracy of approximately 30 centimeters on the Earth's surface. The user's unique identifier is used as the member, and the user's Level-25 S2 code is used as the score. These are stored in the user set structure. For example, using the following ZADD command, "ZADD users3869613036593792000u1," stores user u1 and its location code in a Redis ordered set structure named users.

[0095] All user and location codes (depending on the limitations of the database implementation, different precisions may be used) are stored in the database KV structure, with each user having a unique record. When the user's location is updated, the longitude and latitude of the new location are converted to a location code, and the value associated with the user in the KV structure is updated. The structure after storage is as shown in Table 2:

[0096] Table 2 User and location codes stored in the database KV structure

[0097]

[0098]

[0099] The region range processing module 42 is used to process the region range into multiple value intervals. In this embodiment of the application, the S2 grid is used to cover the region, resulting in multiple grids of different sizes. The rangeMin to rangeMax range of each grid is taken, i.e., the value interval of the S2 code under that grid, and the end-to-end concatenation and compression are performed to obtain multiple one-dimensional value intervals.

[0100] The most common way to describe any geographic area is with a polygon. In particular, a circle can be approximated using a polygon. A polygon can be described as a sequence of vertices, where each vertex is a two-dimensional coordinate consisting of a latitude and longitude. For example, a rectangle with its four vertices arranged clockwise can be represented as the following sequence: (31.365309728100144,120.43889177031652), (31.365309728100144,120.44315111823217), (31.361660168572687,120.44315111823217), (31.361660168572687,120.43889177031652).

[0101] Using the grid coverage algorithm (RegionConverer) provided by S2, input a geographic polygon, select appropriate minimum level (minLevel), maximum level (maxLevel), and maximum grid (maxCells) parameters, and the output result is a set of S2 grids covering the polygon, with each grid level between the minimum level and the maximum level, and the total number of grids within the maximum cell. This process uses the Java SDK code as follows:

[0102] 1.S2RegionCoverer s2RegionCoverer=new S2RegionCoverer();

[0103] 2.s2RegionCoverer.setMinLevel(2);

[0104] 3.s2RegionCoverer.setMaxLevel(20);

[0105] 4.s2RegionCoverer.setMaxCells(10);

[0106] 5.List <s2cellid>s2CellIds=

[0107] s2RegionCoverer.getInteriorCovering(s2Region).cellIds();

[0108] 6.for(S2CellId s2CellId:s2CellIds)

[0109] 7.{System.out.println(s2CellId.id());

[0110] 8.}

[0111] 5A to 5D These are schematic diagrams of the grid coverage graphical effect provided by the embodiments of the present application, wherein: Figure 5A It shows the situation when a maximum of 5 grids are used for coverage. Figure 5B It shows the situation when a maximum of 10 grids are used for coverage. Figure 5C It shows the situation when a maximum of 20 grids are used for coverage. Figure 5D The diagram shows the coverage situation when a maximum of 50 cells are used. The effect of the maximum cell parameter (max cells) on the coverage effect can be seen. Using more cells 51 allows for a more precise fit to the boundaries of polygons 52 (e.g., rectangles), minimizing the extent of the coverage of these cells 51 that extends beyond polygons 52. However, using more cells also results in a more fragmented and discrete range of values ​​for these cells.

[0112] Assuming 10 grids are used for coverage, each grid is converted into a one-dimensional value range, that is, the rangeMin to rangeMax corresponding to each grid is taken. This process is coded as follows using the Java SDK:

[0113] 1.S2CellId rangeMin=s2CellId.rangeMin();

[0114] 2.S2CellId rangeMax=s2CellId.rangeMax();

[0115] 3.System.out.println(rangeMin.id()+"~"+rangeMax.id());

[0116] The following results are obtained by processing these 10 grids as shown in Table 3:

[0117] Table 3 Information on the value intervals corresponding to the 10 grids

[0118]

[0119]

[0120] In combination with the characteristics of S2 encoding, rangeMin and rangeMax are both 30-level codes, with the last (rightmost) bit fixed at 1. Therefore, the range of the above value can be expanded by two invalid values, rangeMin-1 and rangeMax+1, so that the value ranges of adjacent grids are connected end to end, thereby reducing the number of fragments, but the valid values ​​included are completely unchanged. The results after expansion are shown in Table 4:

[0121] Table 4 Information on the value intervals corresponding to the 10 expanded grids

[0122]

[0123]

[0124] After this optimization, the value range can be merged into 5 segments, as shown in Table 5 below:

[0125] Table 5 The five value intervals after the merger

[0126]

[0127] At this point, the input area range is processed into multiple value intervals. The area range covered by the above 10 grids is converted into the following 5 value intervals:

[0128] [3869610766831190016,3869610766965407745] ∪ [3869610768307585024,3869610770455068672] ∪ [3869610779581874176,3869610781729357824] ∪ [3869610782266228736,3869610782803099648] ∪ [3869610806425419776,3869610809646645248]

[0129] The range search user module 43 is used to perform a one-dimensional range search on the user location using multiple value intervals, such as searching for x that meets the conditions a1≤x≤b1 or a2≤x≤b2 or ... or an≤x≤bn, to obtain users in the area coverage grid.

[0130] Searching for matching records based on a value range is an operation required by the "User Location Storage Module" to support a KV-structured database. A database implementation that meets this requirement, namely, Redis's ordered set structure, can be implemented using the zrangeByScore command. For example, if you enter the value range [3869610779581874176,3869610781729357824], you can use the command "ZRANGEBYSCORE users 38696107795818741763869610781729357824WITHSCORES" to retrieve users and their locations. The matching results for the 10 user records are shown in Table 6 below:

[0131] Table 6: 3 matching records found based on 1 value range

[0132] key value u6 3869610780744343071 u7 3869610781522426437 u9 3869610780586528131

[0133] The users and their locations within the five value intervals are queried separately, and the five results are combined. The final set of users within any value interval is shown in Table 7:

[0134] Table 7 User sets found in all value ranges

[0135]

[0136]

[0137] The location area matching module 44 is used to determine whether the area boundary contains the user location for each user screened out by the grid, and retain the included users as the final result within the area boundary.

[0138] Because the grid coverage exceeds the actual area, the user found based on the grid range may be outside the area boundary. This module needs to determine whether the area polygon contains the user's location (S2 grid) to confirm whether the user's location is indeed within the area. The calculation result is true when the polygon boundary completely contains the extremely small grid where the user's location is located (Level-30 grid accuracy is 9 mm). This process uses the Java SDK code as follows:

[0139] 1.S2Cell s2Cell=new S2Cell(new S2CellId(3869610806528482041L));

[0140] 2. / / Whether the polygon completely contains the grid

[0141] 3.boolean contained=s2Polygon.contains(s2Cell);

[0142] 4.System.out.println(contained);

[0143] The calculation results for users within the coverage of the above five grids are:

[0144] Table 7 User sets found in all value ranges

[0145]

[0146]

[0147] According to the results, the users whose locations are within the area are solved, and the final result is: {u6,u7,u9}, that is, users u6, u7, and u9 are located in the target area.

[0148] Since the grid coverage range is expanded compared to the actual target area, the embodiment of the present application determines whether the multi-boundary of the area (modeled as S2Polygon) contains the user location (modeled as S2Cell) for each user screened out by the grid, and retains the included users as the final result within the area boundary. In the process, the user position is coded at level 30 at most, so the overall accuracy can reach up to 9 mm.

[0149] In the embodiment of the present application, on the one hand, the user coding position is fixed and has nothing to do with the user density, the number of users, and the area of ​​user distribution; on the other hand, the same user location data can support area range searches with arbitrary boundaries without adjusting the preprocessing mechanism; thirdly, among a large number of users, incremental updates of user locations are allowed to quickly hit the target in real time.

[0150] The embodiments of the present application have at least the following technical effects: 1) user locations are processed uniformly, and any area range is converted into an interval of one-dimensional values, and there is no need to adjust the user location storage logic according to different query areas; 2) compared with the operation of traversing the grid in sequence used in the known GeoHash grid and Google S2 gridding processing, the embodiments of the present application search for one-dimensional interval values, which greatly improves processing efficiency; 3) different from the related art that uses the grid as an index and stores the user set as a value structure, the embodiments of the present application use the user as the key, and the location of each user can be updated in real time, realizing incremental updates and instant feedback queries; 4) the user location encoding accuracy is 9 mm (the accuracy is 30 cm when using Redis storage), which is better than the 2-meter accuracy of the Level-15+Level-22 two-level index in the related art, and has a wide range of applicability in practical applications.

[0151] The target user query method provided in this embodiment can be applied in scenarios where massive user locations are dynamically updated. It eliminates the need to maintain relationships between users and regions in advance. Users within a specific region can be quickly found based on the input region. This method can be applied to products that target users for real-time insight or reach based on operator location big data.

[0152] Based on the foregoing embodiments, an embodiment of the present application provides a query device for users at a target location. The device includes the modules included and the sub-modules included in each module, which can be implemented by a processor in a computer device; of course, it can also be implemented by a specific logic circuit; in the implementation process, the processor can be a central processing unit (CPU), a microprocessor (MPU), a digital signal processor (DSP) or a field programmable gate array (FPGA), etc.

[0153] Figure 6 A schematic diagram of the structure of a query device for a target location user provided in an embodiment of the present application is shown as follows: Figure 6 As shown, the query device 600 includes: an acquisition module 610, a conversion module 620, a search module 630 and a screening module 640, wherein:

[0154] An acquisition module 610 is used to acquire the target area to be queried;

[0155] A conversion module 620 is configured to convert the target area range into multiple one-dimensional value intervals using an S2 grid covering algorithm;

[0156] A search module 630 is configured to search a set of candidate users whose position codes satisfy the multiple one-dimensional value intervals from a preset grid database; the grid database stores multiple user identifiers and position codes associated with each of the users;

[0157] The screening module 640 is configured to screen the candidate user set using the target area range to determine target users within the target area range.

[0158] In some possible embodiments, the conversion module 620 includes: a first determination submodule, used to determine the N grids covered by the target area range using the S2 grid coverage algorithm; wherein N is less than or equal to a preset maximum number of grids, and the level of each of the grids is between a preset minimum level and a maximum level; a conversion submodule, used to convert the S2 grid code of each of the grids into a one-dimensional value interval; a merging submodule, used to connect the value intervals of adjacent grids in the N grids end to end to obtain M merged one-dimensional value intervals; wherein M is a natural number less than N.

[0159] In some possible embodiments, the device further includes: an encoding module for encoding the two-dimensional coordinates of each of the users using the S2 geographic location encoding system to obtain the location code of the corresponding user; a storage module for storing the identifier of each of the users as a key and the location code of the corresponding user as a value in the grid database.

[0160] In some possible embodiments, the position code is a first-level grid precision, the grid database is an ordered set structure of Redis, and the value of the ordered set structure is a double-precision floating point type. The storage module is also used to convert the position code of the first-level grid precision into a second-level grid precision position code matching the double-precision floating point type for each user; the position code of the second-level grid precision is stored in the ordered set structure as a value associated with the corresponding user; wherein the grid corresponding to the second-level grid precision is the parent grid of the grid corresponding to the first-level grid precision.

[0161] In some possible embodiments, the device further includes an updating module for encoding the updated two-dimensional coordinates in response to the update of the first user's two-dimensional coordinates to obtain a new position code; and using the new position code to update the value associated with the first user in the grid database.

[0162] In some possible embodiments, the search module includes: a search submodule, used to search the grid database for users whose position codes belong to the corresponding one-dimensional value interval for each segment of the one-dimensional value interval, and obtain a query result; the query result includes the user's identifier and the associated position code; a merging submodule, used to merge the query results of the multiple one-dimensional value intervals to obtain the candidate user set.

[0163] In some possible embodiments, the screening module is further configured to, for each candidate user in the candidate user set, determine that the corresponding candidate user is the target user if the boundary of the target area completely includes the minimum grid to which the location of the corresponding candidate user belongs.

[0164] The description of the above device embodiment is similar to the description of the above method embodiment and has similar beneficial effects as the method embodiment. In some embodiments, the functions or modules included in the device provided by the embodiments of the present disclosure can be used to perform the methods described in the above method embodiments. For technical details not disclosed in the device embodiments of this application, please refer to the description of the method embodiments of this application for understanding.

[0165] It should be noted that, in the embodiment of the present application, if the above-mentioned method for querying users at the target location is implemented in the form of a software function module and is sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application, or the part that contributes to the relevant technology, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes various media that can store program codes, such as a U disk, a mobile hard disk, a read-only memory (ROM), a magnetic disk or an optical disk. In this way, the embodiment of the present application is not limited to any specific hardware, software or firmware, or any combination of hardware, software and firmware.

[0166] An embodiment of the present application provides a computer device, including a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the processor executes the program, some or all of the steps in the above method are implemented.

[0167] The present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements some or all of the steps in the above method. The computer-readable storage medium may be transient or non-transient.

[0168] An embodiment of the present application provides a computer program, including computer-readable code. When the computer-readable code is run in a computer device, a processor in the computer device executes some or all of the steps for implementing the above method.

[0169] An embodiment of the present application provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and when the computer program is read and executed by a computer, implements some or all of the steps in the above method. The computer program product can be implemented specifically by hardware, software, or a combination thereof. In some embodiments, the computer program product is embodied as a computer storage medium. In other embodiments, the computer program product is embodied as a software product, such as a software development kit (SDK), etc.

[0170] It should be noted that the descriptions of the various embodiments above tend to emphasize the differences between the various embodiments, and their similarities or similarities can be referenced to each other. The descriptions of the above device, storage medium, computer program, and computer program product embodiments are similar to the descriptions of the above method embodiments and have similar beneficial effects as the method embodiments. For technical details not disclosed in the embodiments of the device, storage medium, computer program, and computer program product of this application, please refer to the description of the method embodiments of this application for understanding.

[0171] It should be noted that Figure 7 A schematic diagram of a hardware entity of a computer device in an embodiment of the present application is shown in FIG. Figure 7 As shown, the hardware entity of the computer device 700 includes: a processor 701, a communication interface 702 and a memory 703, wherein:

[0172] Processor 701 generally controls the overall operation of computer device 700 .

[0173] The communication interface 702 enables the computer device to communicate with other terminals or servers through a network.

[0174] The memory 703 is configured to store instructions and applications executable by the processor 701. It can also cache data to be processed or processed by the processor 701 and various modules in the computer device 700 (for example, image data, audio data, voice communication data, and video communication data). This can be implemented using flash memory (FLASH) or random access memory (RAM). Data can be transmitted between the processor 701, the communication interface 702, and the memory 703 via a bus 704.

[0175] It should be understood that "one embodiment" or "an embodiment" mentioned throughout the specification means that the specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in the various embodiments of the present application, the size of the serial numbers of the above-mentioned steps / processes does not mean the order of execution. The execution order of each step / process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application. The above-mentioned serial numbers of the embodiments of the present application are for description only and do not represent the advantages and disadvantages of the embodiments.

[0176] It should be noted that, in this document, the terms "comprise," "include," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or apparatus comprising a list of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a..." does not preclude the presence of other identical elements in the process, method, article, or apparatus comprising the element.

[0177] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.

[0178] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units; they may be located in one place or distributed across multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the scheme of this embodiment.

[0179] In addition, all functional units in the embodiments of the present application can be integrated into one processing unit, or each unit can be a separate unit, or two or more units can be integrated into one unit; the above-mentioned integrated units can be implemented in the form of hardware or in the form of hardware plus software functional units.

[0180] Those skilled in the art will understand that all or part of the steps of implementing the above-mentioned method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above-mentioned method embodiment; and the aforementioned storage medium includes: mobile storage devices, read-only memories (ROM), magnetic disks or optical disks, and other media that can store program codes.

[0181] Alternatively, if the above-mentioned integrated unit of the present application is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the relevant technology, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a number of instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROMs, magnetic disks, or optical disks.

[0182] The above is only an implementation method of the present application, but the scope of protection of the present application is not limited thereto. Any technician familiar with this technical field can easily think of changes or replacements within the technical scope disclosed in this application, which should be covered by the scope of protection of the present application.

Claims

1. A method for querying users at a target location, characterized in that: The method comprises: Get the target area to be queried; The target area range is converted into multiple one-dimensional value intervals through the S2 grid covering algorithm; Searching for a set of candidate users whose position codes satisfy the multiple one-dimensional value intervals from a preset grid database; the grid database stores identifications of multiple users and position codes associated with each of the users; Filtering the candidate user set using the target area range to determine target users within the target area range; The step of converting the target area range into multiple one-dimensional value intervals using the S2 grid coverage algorithm includes: Determine N grids covered by the target area using the S2 grid coverage algorithm; wherein N is less than or equal to a preset maximum number of grids, and the level of each grid is between a preset minimum level and a preset maximum level; Converting the S2 grid code of each grid into a one-dimensional value interval; Connecting the value intervals of adjacent grids in the N grids end to end to obtain M merged one-dimensional value intervals; wherein M is a natural number smaller than N; The searching for a set of candidate users whose position codes satisfy the multiple one-dimensional value intervals from a preset grid database includes: For each one-dimensional value interval, searching the grid database for users whose location codes fall within the corresponding one-dimensional value interval to obtain a query result; the query result includes the user's identifier and the associated location code; The query results of the multiple one-dimensional value intervals are merged to obtain the candidate user set.

2. The method according to claim 1, characterized in that The method further comprises: Encoding the two-dimensional coordinates of each user using the S2 geographic location coding system to obtain a location code corresponding to the user; The identifier of each user is used as a key, and the position of the corresponding user is encoded as a value and stored in the grid database.

3. The method according to claim 2, characterized in that The position code is of first-level grid precision, the grid database is an ordered set structure of Redis, the value of the ordered set structure is a double-precision floating point type, and the method further includes: For each of the users, converting the position code of the first-level grid precision into the position code of the second-level grid precision matching the double-precision floating-point type; The position code of the second-level grid precision is stored in the ordered set structure as a value associated with the corresponding user; wherein the grid corresponding to the second-level grid precision is the parent grid of the grid corresponding to the first-level grid precision.

4. The method according to claim 2, characterized in that The method further comprises: In response to the update of the two-dimensional coordinates of the first user, encoding the updated two-dimensional coordinates to obtain a new position code; The value associated with the first user in the grid database is updated using the new location code.

5. The method according to any one of claims 1 to 4, characterized in that The step of screening the candidate user set by using the target area range to determine the target user located within the target area range includes: For each candidate user in the candidate user set, if the boundary of the target area completely includes the minimum grid to which the location of the corresponding candidate user belongs, the corresponding candidate user is determined to be the target user.

6. A query device for a user at a target location, characterized in that: The device comprises: The acquisition module is used to obtain the target area range to be queried; A conversion module, configured to convert the target area range into multiple one-dimensional value intervals through an S2 grid covering algorithm; A search module is used to search a set of candidate users whose position codes satisfy the multiple one-dimensional value intervals from a preset grid database; the grid database stores multiple user identifiers and position codes associated with each of the users; A screening module, configured to screen the candidate user set using the target area range to determine target users within the target area range; The conversion module includes a first determination submodule, a conversion submodule, and a merging submodule. The first determination submodule is used to determine the N grids covered by the target area using the S2 grid coverage algorithm; wherein N is less than or equal to a preset maximum number of grids, and the level of each grid is between a preset minimum level and a preset maximum level; the conversion submodule is used to convert the S2 grid code of each grid into a one-dimensional value interval; the merging submodule is used to connect the value intervals of adjacent grids in the N grids end to end to obtain M merged one-dimensional value intervals; wherein M is a natural number less than N; The search module includes a search submodule, which is used to search the grid database for users whose position codes belong to the corresponding one-dimensional value interval for each segment of the one-dimensional value interval to obtain a query result; the query result includes the user's identifier and the associated position code; the merging submodule is used to merge the query results of the multiple one-dimensional value intervals to obtain the candidate user set.

7. A computer device comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, characterized in that: When the processor executes the program, the steps of the method according to any one of claims 1 to 5 are implemented.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.

Citation Information

Patent Citations

  • Region positioning method and device, equipment and storage medium

    CN114238384A

  • Spatial data retrieval method and device, electronic equipment and storage medium

    CN114880350A