A distance calculation method, device and electronic equipment based on area division
By dividing areas and storing distance information on the server side, the problem of low efficiency in distance calculation due to high concurrency is solved, fast response and efficient distance calculation are achieved, and the user experience of mobile navigation is improved.
Patent Information
- Application Number
- CN202010932545.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-09-08
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2040-09-08
AI Technical Summary
The existing technology has low efficiency and untimely response due to high concurrency in distance calculations, which limits the real-time feedback of data and affects the user experience of mobile navigation and the demand for intelligent services.
By dividing a specific area on the server side, the distance from the regional center position of each sub-area to each preset target point is obtained and stored. When the user requests, the corresponding distance is obtained directly from the storage to avoid repeated calculations and is fast. Feedback the distance between the current position and the target point.
It achieves high efficiency and rapid response in distance calculation, improves the user experience of mobile navigation, and meets users' real-time needs for intelligent services.
Smart Images

Figure CN112214563B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of distance calculation, and in particular to a distance calculation method, device and electronic equipment based on area division. Background Art
[0002] In the field of Internet services, users use mobile applications to perceive regional distance information, view real-time locations, and navigate. How to efficiently respond to user requests and quickly obtain target location distance information is a key concern.
[0003] However, the inventors of this application found that the above-mentioned prior art has at least the following technical problems in the process of implementing the technical solutions in the embodiments of this application:
[0004] In the existing technology, the efficiency of distance calculation is low and the response is not timely under high concurrency, which limits the real-time feedback of data and cannot well improve the mobile navigation user experience, thus limiting the user demand for intelligent services to a certain extent. Summary of the invention
[0005] The embodiments of the present application provide a distance calculation method, device and electronic device based on area division, which solves the technical problems in the prior art that distance calculation is inefficient and responsive under high concurrency, limits real-time feedback of data, cannot improve the mobile navigation user experience, and limits the user's demand for intelligent services to a certain extent.
[0006] In the first aspect, the present application provides the following technical solutions through an embodiment of the present application:
[0007] A distance calculation method based on area division is applied to a server, the server is connected to a client, and the method comprises: obtaining the coordinates of a boundary position point of a specific area to obtain a first result; based on the first result and a target preset unit, dividing the specific area into areas to obtain a second result, wherein the second result is an area including multiple sub-areas; determining the coordinates of the area center position of each of the sub-areas to obtain a third result; based on the third result, obtaining the distance from the area center position of each of the sub-areas to each preset target point to obtain a fourth result; obtaining a distance request from the client, wherein the distance request includes a user's current position and a target point, wherein the target point is one of the preset target points; determining the sub-area where the current position is located in the second result to obtain a fifth result; based on the fourth result and the fifth result, determining the distance between the current position and the target point, and sending it to the client.
[0008] In one embodiment, the specific area is divided into regions based on the first result and the target preset unit to obtain a second result, including: based on the first result, the specific area is divided into N levels of regions to obtain a sixth result, and the sixth result includes the regions obtained after each level of regional division; based on the target preset unit, the specific area is divided into N+1 levels of regions to obtain the second result, and the second result is a region including multiple N+1 sub-regions.
[0009] In one embodiment, based on the first result, the specific area is divided into N levels to obtain a sixth result, and the sixth result includes the areas obtained after each level of regional division, including: according to the first preset unit and the first result, the specific area is divided into the first level to obtain a first area, and the first area is an area including multiple first sub-areas; according to the second preset unit, each of the first sub-areas in the first area is divided into the second level to obtain a second area, and the second area is an area including multiple second sub-areas; and so on, until according to the Nth preset unit, each N-1th sub-area of the N-1th area is divided into the Nth level to obtain the Nth area, and the Nth area is an area including multiple Nth sub-areas, wherein the sixth result includes each area from the first area to the Nth area.
[0010] In one embodiment, based on the target preset unit, each of the Nth sub-regions is divided into regions to obtain the second result, and the second result is a region including multiple N+1th sub-regions, including: based on the target preset unit, each of the Nth sub-regions in the Nth region is divided into the N+1th level of regions to obtain the N+1th region, and the N+1th region is the second result.
[0011] In one embodiment, before determining the sub-region where the current position is located in the second result to obtain the fifth result, it also includes: obtaining the coordinates of the center position of each i-th sub-region in the i-th region, where i is a positive integer from 1 to N in sequence.
[0012] In one embodiment, determining the sub-region where the current position is located in the second result to obtain a fifth result includes: obtaining the coordinates of the area center position of each i-th sub-region within the target sub-region where the i-th region is located, the target sub-region being the i-1th sub-region where the current position is located in the i-1th region; based on the coordinates of the area center position of each i-th sub-region within the target sub-region, determining the distance between the current position and the area center position of each i-th sub-region within the target sub-region to obtain a seventh result; based on the seventh result, determining the i-th sub-region where the current position is located within the i-th region, wherein i takes positive integers from 1 to N in sequence until the Nth sub-region where the current position is located in the N+1th region is determined, and when i takes 1, the target sub-region is the specific region.
[0013] In one embodiment, determining the coordinates of the regional center position of each of the sub-regions to obtain a third result includes: determining the coordinates of the regional center position of each of the N+1th sub-regions to obtain the third result; and obtaining the distance from the regional center position of each of the sub-regions to each preset target point based on the third result to obtain a fourth result, including: obtaining the distance from the regional center position of each of the N+1th sub-regions to each preset target point based on the third result to obtain the fourth result.
[0014] In the second aspect, the present application provides the following technical solution through an embodiment of the present application:
[0015] A distance calculation device based on area division is applied to a server, the server is connected to a client, and the device comprises: a first acquisition unit, used to acquire the coordinates of a boundary position point of a specific area to obtain a first result; a division unit, used to divide the specific area into regions according to the first result and a target preset unit to obtain a second result, wherein the second result is a region including multiple sub-regions; a first determination unit, used to determine the coordinates of the region center position of each of the sub-regions to obtain a third result; a second acquisition unit, used to acquire the distance from the region center position of each of the sub-regions to each preset target point according to the third result to obtain a fourth result; a third acquisition unit, used to acquire a distance request from the client, wherein the distance request includes a user's current position and a target point, wherein the target point is one of the preset target points; a second determination unit, used to determine the sub-region where the current position is located in the second result to obtain a fifth result; and a third determination unit, used to determine the distance between the current position and the target point according to the fourth result and the fifth result, and send the distance to the client.
[0016] In a third aspect, the present application provides the following technical solutions through an embodiment of the present application:
[0017] An electronic device comprises: a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor can implement the method steps described in any of the above embodiments when executing the program.
[0018] In a fourth aspect, the present application provides the following technical solutions through an embodiment of the present application:
[0019] A computer-readable storage medium stores a computer program, including: when the program is executed by a processor, the method steps described in any of the above embodiments can be implemented.
[0020] One or more technical solutions provided in the embodiments of the present application have at least the following technical effects or advantages:
[0021] In the distance calculation method based on area division provided by the present application, after a specific area is divided into areas based on a target preset unit, an area including multiple sub-areas is obtained, and then the distance from the area center position of each sub-area to each preset target point is obtained and stored. When the user sends a distance request carrying the current position and the target point to the server through the client, it is first determined in which sub-area the current position is located. After the determination is made, the stored distance between the sub-area and the target point is directly called to determine the distance between the current position and the target point, and the distance is fed back to the client. In the present application, compared with the high concurrency of distance calculation in the prior art, the present application implements the storage of the distance between each sub-area and each preset target point, so that when the user requests, the distance does not need to be calculated, and the distance between the user's current position and the target point can be obtained by judging which sub-area the user's current position belongs to. Therefore, the present application has the characteristics of high efficiency and timely response, and solves the technical problems of low efficiency and untimely response under high concurrency of distance calculation in the prior art, limiting the real-time feedback of data, failing to well improve the mobile navigation user experience, and limiting the user's demand for intelligent services to a certain extent. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0023] Figure 1 A flowchart of a distance calculation method based on area division provided in Example 1 of the present application;
[0024] Figure 2 This is an architecture diagram of a distance calculation device based on area division provided in Embodiment 2 of the present application;
[0025] Figure 3 This is an architecture diagram of an electronic device provided in Example 3 of the present application;
[0026] Figure 4 An architectural diagram of a computer-readable storage medium provided for Embodiment 4 of the present application. DETAILED DESCRIPTION
[0027] The embodiments of the present application provide a distance calculation method, device and electronic device based on area division, which solves the technical problems in the prior art that distance calculation is inefficient and responsive under high concurrency, limits real-time feedback of data, cannot improve the mobile navigation user experience, and limits the user's demand for intelligent services to a certain extent.
[0028] The technical solution of the embodiment of the present application is to solve the above technical problems, and the overall idea is as follows:
[0029] In the distance calculation method based on area division provided by the present application, after a specific area is divided into areas based on a target preset unit, an area including multiple sub-areas is obtained, and then the distance from the area center position of each sub-area to each preset target point is obtained and stored. When the user sends a distance request carrying the current position and the target point to the server through the client, it is first determined in which sub-area the current position is located. After the determination is made, the stored distance between the sub-area and the target point is directly called to determine the distance between the current position and the target point, and the distance is fed back to the client. In the present application, compared with the high concurrency of distance calculation in the prior art, the present application implements the storage of the distance between each sub-area and each preset target point, so that when the user requests, the distance does not need to be calculated, and the distance between the user's current position and the target point can be obtained by judging which sub-area the user's current position belongs to. Therefore, the present application has the characteristics of high efficiency and timely response, and solves the technical problems of low efficiency and untimely response under high concurrency of distance calculation in the prior art, limiting the real-time feedback of data, failing to well improve the mobile navigation user experience, and limiting the user's demand for intelligent services to a certain extent.
[0030] In order to better understand the above technical solution, the above technical solution will be described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0031] Embodiment 1
[0032] like Figure 1 As shown, this embodiment provides a distance calculation method based on area division, which is applied to a server, and the server is connected to a client. The method includes:
[0033] Step S101: Acquire the coordinates of the boundary position points of a specific area to obtain a first result.
[0034] In actual implementation, the specific area is a rectangular area. When the area where the field is located is an irregular area, the edge area is drawn in to form a rectangular area. Step S101 specifically includes: obtaining the coordinates of the four corner points of the rectangular area. The first result includes the coordinates of the four corner points.
[0035] As an example, the four corner points of a rectangular area are as follows:
[0036] Corner point 1: Latitude and longitude - (39.92300, 116.15120)
[0037] Corner point 2: Latitude and longitude - (39.92300, 116.15590)
[0038] Corner point 3: Latitude and longitude - (39.91940, 116.15590)
[0039] Corner point 4: Latitude and longitude - (39.91940, 116.15120)
[0040] Furthermore, based on code 1, the side length of the rectangular area is obtained as follows:
[0041] Code 1:
[0042] double lat1=Math.toRadians(latitude1);
[0043] double lat2=Math.toRadians(latitude2);
[0044] double lng1=Math.toRadians(longitude1);
[0045] double lng2=Math.toRadians(longitude2);
[0046] double a=lat1-lat2;
[0047] double b=lng1-lng2;
[0048] double s=2*Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2),2)+Math.cos(lat1)*Math.cos(lat2)*Math.pow(Math.sin(b / 2),2)));
[0049] double distance=s*EARTH_RADIUS*1000;
[0050] Among them, EARTH_RADIUS is the radius of the earth, the coordinates of position point 1 are (latitude1, longtude1), the coordinates of position point 2 are (latitude2, longtude2), and distance is the distance between the two points.
[0051] Using the above code 1, the distance from corner point 1 to corner point 2 is 400 meters; the distance from corner point 1 to corner point 3 is 400 meters.
[0052] Step S102: Based on the first result and the target preset unit, the specific area is divided into regions to obtain a second result, where the second result is a region including a plurality of sub-regions.
[0053] In a specific application, the specific area is a rectangular area, and the specific area is equally divided based on the target preset unit to obtain multiple sub-areas, and each sub-area is also a rectangle, and based on the first result, the coordinates of the boundary position points of each sub-area can be obtained, and then the second result is obtained. The target preset unit here refers to the side length of the sub-area into which the rectangular area is divided.
[0054] As an optional embodiment, step S102 includes:
[0055] Based on the first result, the specific area is divided into N levels to obtain a sixth result, where the sixth result includes areas obtained after each level of regional division.
[0056] Based on the target preset unit, the specific area is divided into an N+1th level area to obtain a second result, where the second result is an area including a plurality of N+1th sub-areas.
[0057] In a specific implementation process, based on the first result, the specific area is divided into N levels to obtain a sixth result. The sixth result includes the areas obtained after each level of regional division, including:
[0058] According to the first preset unit and the first result, the specific area is divided into a first level area to obtain a first area, where the first area is an area including a plurality of first sub-areas;
[0059] According to the second preset unit, performing a second-level region division on each first sub-region in the first region to obtain a second region, where the second region is a region including a plurality of second sub-regions;
[0060] And so on, until each N-1th sub-region of the N-1th region is divided into the Nth level according to the Nth preset unit to obtain the Nth region, where the Nth region is a region including multiple Nth sub-regions, wherein the sixth result includes each region from the first region to the Nth region.
[0061] As an example, the above example is used to divide the above rectangular area into three levels to obtain the sixth result, and cache each division result, as follows:
[0062] The first-level area is divided and cached: the first preset unit is 100 meters. After the specific area is divided, a total of 16 first sub-areas are obtained. The area composed of the 16 first sub-areas is the first area. The coordinates of the boundary position points of each first sub-area in the first area are stored.
[0063] Then, the coordinates of the center position of each first sub-region are calculated according to code 2, as follows:
[0064] Code 2:
[0065] doubleδ=D / EARTH_RADIUS;
[0066] angle=Math.toRadians(angle);
[0067] longtude1=Math.toRadians(longtude1);
[0068] latitude1=Math.toRadians(latitude1);
[0069] double lat=Math.asin(Math.sin(latitude1)*Math.cos(δ)+Math.cos(latitude1)*Math.sin(δ)*Math.cos(angle));
[0070] double lon=longtude1+Math.atan2(Math.sin(angle)*Math.sin(δ)*Math.cos(latitude1),Math.cos(δ)-Math.sin(latitude1)*Math.sin(lat));
[0071] lon = Math.toDegrees(lon);
[0072] lat = Math.toDegrees(lat);
[0073] DecimalFormat df=new DecimalFormat("0.000000");
[0074] String resultLon=df.format(lon);
[0075] String resultLat=df.format(lat);
[0076] Among them, (latitude1, longtude1) are the coordinates of the known position point, in this example, they are the coordinates of a corner point of the sub-region, D is half the length of the side of the sub-region, angle is the vertical or horizontal position of the center point of the sub-region in relation to the known position point, and the coordinates used to determine the center point of the sub-region should be added or subtracted based on the coordinates of the known position point, (resulitLat, resultLon) are the coordinates of the position point to be determined, in this example, they are the coordinates of the center point of the sub-region.
[0077] Based on the above code 2, the coordinates of the center position of each first sub-region are calculated as follows:
[0078] Center point of the first sub-area 1: Latitude and longitude - (39.922550, 116.151786)
[0079] Center point of the first sub-area 2: Latitude and longitude - (39.922550, 116.152959)
[0080] Center point of the first sub-area 3: Latitude and longitude - (39.922550, 116.154132)
[0081] Center point of the first sub-area 4: Latitude and longitude - (39.922550, 116.155304)
[0082] They are not listed here one by one.
[0083] Then the second-level area division is performed and cached: the second preset unit is 25 meters. After dividing each first sub-area in the first area, a total of 16*16=256 second sub-areas are obtained. The area composed of the 256 second sub-areas is the second area, and the coordinates of the boundary position points of each second sub-area in the second area are stored.
[0084] Then, the coordinates of the center position of each second sub-region are calculated according to the above code 2. This example only shows the coordinates of the center positions of the four second sub-regions in the first sub-region 1, as follows:
[0085] Second sub-area 1 center point: latitude and longitude - (39.922888, 116.151347)
[0086] Second sub-area 2 center point: latitude and longitude - (39.922888, 116.151640)
[0087] Second sub-area 3 center point: latitude and longitude - (39.922888, 116.151933)
[0088] Second sub-area 4 center point: latitude and longitude - (39.922888, 116.152226)
[0089] They are not listed here one by one.
[0090] Then the third level area division is performed and cached:
[0091] The third preset unit is 5 meters. After dividing each second sub-area in the second area, a total of 256*25=6400 third sub-areas are obtained. The area composed of the 6400 third sub-areas is the third area, and the coordinates of the boundary position points of each third sub-area in the third area are stored.
[0092] Then, the coordinates of the center position of each third sub-region are calculated according to the above code 2. This example only shows the coordinates of the center positions of the five third sub-regions in the second sub-region 1, as follows:
[0093] The center point of the third sub-area 1: latitude and longitude - (39.922978, 116.151229)
[0094] The center point of the third sub-area 2: latitude and longitude - (39.922978, 116.151288)
[0095] The third sub-area 3 center point: latitude and longitude - (39.922978, 116.151347)
[0096] The third sub-area 4 center point: latitude and longitude - (39.922978, 116.151405)
[0097] The third sub-area 5 center point: latitude and longitude - (39.922978, 116.151464)
[0098] They are not listed here one by one.
[0099] At this point, a sixth result is obtained, which includes the first area, the second area, and the third area.
[0100] As an optional embodiment, based on the target preset unit, each Nth sub-region is divided into regions to obtain a second result, where the second result is a region including multiple N+1th sub-regions, including:
[0101] Based on the target preset unit, each Nth sub-region in the Nth region is divided into an N+1th level region to obtain an N+1th region, and the N+1th region is the second result.
[0102] As an example, continue to use the above example, and divide the fourth level of regions based on the third region and perform caching:
[0103] The target preset unit is 1 meter. After dividing each third sub-area in the third area, a total of 6400*25=160,000 fourth sub-areas are obtained. The area composed of the 160,000 fourth sub-areas is the fourth area, and the coordinates of the boundary position points of each fourth sub-area in the fourth area are stored.
[0104] Step S103: Determine the coordinates of the region center position of each sub-region to obtain a third result.
[0105] As an optional embodiment, step S103 includes:
[0106] The coordinates of the region center position of each N+1th sub-region are determined to obtain a third result.
[0107] During the specific implementation, the coordinates of the center position of each N+1th sub-region are calculated according to code 2.
[0108] Continuing with the above example, the coordinates of the center position of each fourth sub-region are calculated according to the above code 2. This example only shows the coordinates of the center positions of the five fourth sub-regions in the third sub-region 1, as follows:
[0109] Center point of the fourth sub-area 1: Latitude and longitude - (39.922996, 116.151206)
[0110] Center point of the fourth sub-area 2: Latitude and longitude - (39.922996, 116.151218)
[0111] Center point of the fourth sub-area 3: Latitude and longitude - (39.922996, 116.151229)
[0112] The fourth sub-area 4 center point: latitude and longitude - (39.922996, 116.151241)
[0113] The fourth sub-area 5 center point: latitude and longitude - (39.922996, 116.151253)
[0114] They are not listed here one by one.
[0115] Step S104: Based on the third result, the distance from the center position of each sub-region to each preset target point is obtained to obtain a fourth result.
[0116] As an optional embodiment, step S104 includes:
[0117] Based on the third result, the distance from the area center position of each N+1th sub-area to each preset target point is obtained to obtain a fourth result.
[0118] Before step S104, the method further includes: obtaining the coordinates of each preset target point. Each preset target point can be input by an administrator through a provided interface.
[0119] As an example, the preset target points include 5 target points, as follows:
[0120] Target point 1: Latitude and longitude - (39.922696, 116.152907)
[0121] Target point 2: Latitude and longitude - (39.921978, 116.151444)
[0122] Target point 3: Latitude and longitude - (39.920941, 116.151822)
[0123] Target point 4: Latitude and longitude - (39.920366, 116.153276)
[0124] Target point 5: Latitude and longitude - (39.922996, 116.151253).
[0125] Using the above example, the distance from the center position of each fourth sub-region to each of the above target points is calculated according to code 1. This example only shows the distance from the fourth sub-regions 1, 3, and 5 to each target point, as follows:
[0126] The center point of the fourth sub-area 1: Latitude and longitude - (39.922996, 116.151206) Distance to each target point:
[0127] [149 meters, 115 meters, 235 meters, 342 meters, 455 meters]
[0128] The center point of the fourth sub-area 3: Latitude and longitude - (39.922996, 116.151229) Distance to each target point:
[0129] [147 meters, 115 meters, 234 meters, 341 meters, 454 meters]
[0130] The center point of the fourth sub-area 5: Latitude and longitude - (39.922996, 116.151675) Distance to each target point:
[0131] [145 meters, 114 meters, 234 meters, 340 meters, 452 meters]
[0132] They are not listed here one by one.
[0133] In this example, the distance from the center of the fourth sub-region to each target point is a straight-line distance. This distance can be calculated based on actual user needs and is not limited to Formula 1. Existing interfaces can also be called to calculate the actual distance and store it.
[0134] Step S105: Obtain a distance request from the client, where the distance request includes the user's current location and a target point, where the target point is one of the preset target points.
[0135] Step S106: Determine the sub-region where the current position is located in the second result to obtain a fifth result.
[0136] As an optional embodiment, before step S106, the method further includes:
[0137] The coordinates of the region center position of each i-th sub-region in the i-th region are obtained, where i is a positive integer from 1 to N.
[0138] As an optional embodiment, step S106 includes:
[0139] Get the coordinates of the center position of each i-th sub-region of the i-th region within the target sub-region, where the target sub-region is the i-1-th sub-region where the current position is within the i-1-th region;
[0140] Based on the coordinates of the region center position of each i-th sub-region within the target sub-region, determine the distances between the current position and the region center position of each i-th sub-region within the target sub-region, to obtain a seventh result;
[0141] Based on the seventh result, determine the i-th sub-region where the current position is located in the i-th region, where i takes positive integers from 1 to N in sequence, until it is determined that the current position is in the N-th sub-region of the N+1 region, and when i takes 1, the target sub-region is a specific region.
[0142] In a specific application, based on the minimum value in the seventh result, the i-th sub-region where the current position is located in the i-th region is determined.
[0143] As an example, the user's current location is latitude and longitude - (39.922991, 116.151229), which is within a specific area. At this time, the coordinates of the center point of each first sub-area of the first area within the specific area are obtained, that is, the coordinates of the center points of the four first sub-areas need to be obtained, which are:
[0144] Center point of the first sub-area 1: latitude and longitude - (39.922550, 116.151786);
[0145] Center point of the first sub-area 2: latitude and longitude - (39.922550, 116.152959);
[0146] Center point of the first sub-area 3: latitude and longitude - (39.922550, 116.154132);
[0147] Center point of the first sub-area 4: latitude and longitude - (39.922550, 116.155304).
[0148] According to Formula 1, the distances from the current position to the center points of the four first sub-regions are calculated, which are: [68.35 meters, 155.64 meters, 252.65 meters, 351.34 meters], respectively. It can be obtained that the user's current position is in the first sub-region 1 in the first region.
[0149] Next, the coordinates of the center point of each second sub-region of the second region within the first sub-region 1 are obtained, that is, the coordinates of the center points of four second sub-regions need to be obtained, which are:
[0150] The center point of the second sub-area 1: latitude and longitude - (39.922888, 116.151347);
[0151] Second sub-area 2 center point: latitude and longitude - (39.922888, 116.151640);
[0152] Second sub-area 3 center point: latitude and longitude - (39.922888, 116.151933);
[0153] Center point of the second sub-area 4: latitude and longitude - (39.922888, 116.152226).
[0154] According to Formula 1, the distances from the current position to the center points of the four second sub-regions are calculated, which are: [15.26 meters, 36.91 meters, 61.19 meters, 85.88 meters], respectively. It can be obtained that the user's current position is in the second sub-region 1 within the second region.
[0155] Next, the coordinates of the center points of each third sub-region of the third region within the second sub-region 1 are obtained, that is, the coordinates of the center points of five third sub-regions need to be obtained, which are:
[0156] The center point of the third sub-area 1: latitude and longitude - (39.922978, 116.151229);
[0157] The center point of the third sub-area 2: latitude and longitude - (39.922978, 116.151288);
[0158] The third sub-area 3 center point: latitude and longitude - (39.922978, 116.151347);
[0159] The third sub-area 4 center point: latitude and longitude - (39.922978, 116.151405);
[0160] The center point of the third sub-area 5: latitude and longitude - (39.922978, 116.151464).
[0161] According to Formula 1, the distances from the current position to the center points of the five third sub-regions are calculated, which are: [1.45 meters, 5.24 meters, 10.18 meters, 15.09 meters, 20.11 meters]. It can be obtained that the user's current position is in the third sub-region 1 within the third region.
[0162] Finally, the coordinates of the center points of each fourth sub-region of the fourth region within the third sub-region 1 are obtained, that is, the coordinates of the center points of five fourth sub-regions need to be obtained, which are:
[0163] Center point of the fourth sub-area 1: Latitude and longitude - (39.922996, 116.151206)
[0164] Center point of the fourth sub-area 2: Latitude and longitude - (39.922996, 116.151218)
[0165] Center point of the fourth sub-area 3: Latitude and longitude - (39.922996, 116.151229)
[0166] The fourth sub-area 4 center point: latitude and longitude - (39.922996, 116.151241)
[0167] The fourth sub-area 5 center point: latitude and longitude - (39.922996, 116.151253)
[0168] According to Formula 1, the distances from the current position to the center points of the five third sub-regions are calculated, which are: [2.04 meters, 1.09 meters, 0.56 meters, 1.17 meters, 2.12 meters], respectively. It can be obtained that the user's current position is in the fourth sub-region 3 within the fourth region.
[0169] Step S107: Based on the fourth result and the fifth result, determine the distance between the current position and the target point, and send it to the client.
[0170] Specifically, based on the fifth result, the N+1th sub-region where the current position is located can be determined, and based on the fourth result, the distance from the center position of the N+1th sub-region where the current position is located to the target point can be obtained, and the distance is fed back to the client.
[0171] Continuing with the above example, based on the fifth result, it is determined that the user's current location is in the fourth sub-area 3 within the fourth area, and the center position of the fourth sub-area 3 is: latitude and longitude - (39.922996, 116.151229)
[0172] If the target points are:
[0173] Target point 1: Latitude and longitude - (39.922696, 116.152907);
[0174] Target point 2: latitude and longitude - (39.921978, 116.151444);
[0175] Target point 3: Latitude and longitude - (39.920941, 116.151822);
[0176] Target point 4: Latitude and longitude - (39.920366, 116.153276);
[0177] Target point 5: Latitude and longitude - (39.922996, 116.151253).
[0178] Based on the fourth result, the query obtains that the distances from the center position of the four sub-regions 3 to the above five target points are: [147 meters, 115 meters, 234 meters, 341 meters, 454 meters], which are used as the distances from the user's current position to each target point and fed back to the client.
[0179] The technical solutions in the above embodiments of the present application have at least the following technical effects or advantages:
[0180] In the distance calculation method based on area division provided by the present application, after a specific area is divided into areas based on a target preset unit, an area including multiple sub-areas is obtained, and then the distance from the area center position of each sub-area to each preset target point is obtained and stored. When the user sends a distance request carrying the current position and the target point to the server through the client, it is first determined in which sub-area the current position is located. After the determination is made, the stored distance between the sub-area and the target point is directly called to determine the distance between the current position and the target point, and the distance is fed back to the client. In the present application, compared with the high concurrency of distance calculation in the prior art, the present application implements the storage of the distance between each sub-area and each preset target point, so that when the user requests, the distance does not need to be calculated, and the distance between the user's current position and the target point can be obtained by judging which sub-area the user's current position belongs to. Therefore, the present application has the characteristics of high efficiency and timely response, and solves the technical problems of low efficiency and untimely response under high concurrency of distance calculation in the prior art, limiting the real-time feedback of data, failing to well improve the mobile navigation user experience, and limiting the user's demand for intelligent services to a certain extent.
[0181] Embodiment 2
[0182] Based on the same inventive concept as the distance calculation method based on area division in the aforementioned embodiment, Figure 2 As shown, this embodiment provides a distance calculation device based on area division, which is applied to a server, the server is connected to a client, and the device includes:
[0183] A first acquisition unit 201 is used to acquire the coordinates of a boundary point of a specific area to obtain a first result;
[0184] A division unit 202 is used to divide the specific area into regions according to the first result and the target preset unit to obtain a second result, where the second result is a region including a plurality of sub-regions;
[0185] A first determining unit 203 is used to determine the coordinates of the region center position of each sub-region to obtain a third result;
[0186] The second acquisition unit 204 is used to acquire the distance from the center position of each sub-region to each preset target point according to the third result to obtain a fourth result;
[0187] The third acquisition unit 205 is used to acquire a distance request from the client, where the distance request includes the user's current location and a target point, where the target point is one of the preset target points;
[0188] A second determining unit 206, configured to determine a sub-region where the current position is located in the second result, to obtain a fifth result;
[0189] The third determining unit 207 is used to determine the distance between the current position and the target point according to the fourth result and the fifth result, and send the distance to the client.
[0190] As an optional embodiment, the dividing unit 202 is further configured to:
[0191] Based on the first result, the specific area is divided into N levels to obtain a sixth result, where the sixth result includes the areas obtained after each level of regional division;
[0192] Based on the target preset unit, the specific area is divided into an N+1th level area to obtain a second result, where the second result is an area including a plurality of N+1th sub-areas.
[0193] As an optional embodiment, the dividing unit 202 is further configured to:
[0194] According to the first preset unit and the first result, the specific area is divided into a first level area to obtain a first area, where the first area is an area including a plurality of first sub-areas;
[0195] According to the second preset unit, performing a second-level region division on each first sub-region in the first region to obtain a second region, where the second region is a region including a plurality of second sub-regions;
[0196] And so on, until each N-1th sub-region of the N-1th region is divided into the Nth level according to the Nth preset unit to obtain the Nth region, where the Nth region is a region including multiple Nth sub-regions, wherein the sixth result includes each region from the first region to the Nth region.
[0197] As an optional embodiment, the dividing unit 202 is further configured to:
[0198] Based on the target preset unit, each Nth sub-region in the Nth region is divided into an N+1th level region to obtain an N+1th region, and the N+1th region is the second result.
[0199] As an optional embodiment, the device further includes: an obtaining unit, configured to:
[0200] Before determining the subregion where the current position is located in the second result and obtaining the fifth result, the coordinates of the region center position of each i-th subregion in the i-th region are obtained, where i is a positive integer from 1 to N in sequence.
[0201] As an optional embodiment, the second determining unit 206 is further configured to:
[0202] Get the coordinates of the center position of each i-th sub-region of the i-th region within the target sub-region, where the target sub-region is the i-1-th sub-region where the current position is within the i-1-th region;
[0203] Based on the coordinates of the region center position of each i-th sub-region within the target sub-region, determine the distances between the current position and the region center position of each i-th sub-region within the target sub-region, to obtain a seventh result;
[0204] Based on the seventh result, determine the i-th sub-region where the current position is located in the i-th region, where i takes positive integers from 1 to N in sequence, until it is determined that the current position is in the N-th sub-region of the N+1 region, and when i takes 1, the target sub-region is a specific region.
[0205] As an optional embodiment, the first determining unit 203 is further configured to:
[0206] Determine the coordinates of the center position of each N+1th sub-region to obtain a third result;
[0207] The second acquisition unit 204 is further configured to:
[0208] Based on the third result, the distance from the area center position of each N+1th sub-area to each preset target point is obtained to obtain a fourth result.
[0209] The technical solutions in the above embodiments of the present application have at least the following technical effects or advantages:
[0210] In the distance calculation device based on area division provided by the present application, after a specific area is divided into areas based on a target preset unit, an area including multiple sub-areas is obtained, and then the distance from the area center position of each sub-area to each preset target point is obtained and stored. When the user sends a distance request carrying the current position and the target point to the server through the client, it is first determined in which sub-area the current position is located. After the determination is made, the stored distance between the sub-area and the target point is directly called to determine the distance between the current position and the target point, and the distance is fed back to the client. In the present application, compared with the high concurrency of distance calculation in the prior art, the present application implements the storage of the distance between each sub-area and each preset target point, so that when the user requests, the distance does not need to be calculated, and the distance between the user's current position and the target point can be obtained by judging which sub-area the user's current position belongs to. Therefore, the present application has the characteristics of high efficiency and timely response, and solves the technical problems of low efficiency and untimely response under high concurrency of distance calculation in the prior art, limiting the real-time feedback of data, failing to well improve the mobile navigation user experience, and limiting the user's demand for intelligent services to a certain extent.
[0211] Embodiment 3
[0212] Based on the same inventive concept as the distance calculation method based on area division in the aforementioned embodiment, Figure 3 As shown, this embodiment provides an electronic device 300, including: a memory 310, a processor 320, and a computer program 311 stored in the memory 310 and executable on the processor 320. When the processor 320 executes the program 311, the following method steps can be implemented:
[0213] Obtain the coordinates of the boundary position point of the specific area to obtain a first result; based on the first result and the target preset unit, divide the specific area into regions to obtain a second result, where the second result is a region including multiple sub-regions; determine the coordinates of the region center position of each sub-region to obtain a third result; based on the third result, obtain the distance from the region center position of each sub-region to each preset target point to obtain a fourth result; obtain a distance request from the client, where the distance request includes the user's current position and the target point, where the target point is one of the preset target points; determine the sub-region where the current position is located in the second result to obtain a fifth result; based on the fourth result and the fifth result, determine the distance between the current position and the target point, and send it to the client.
[0214] In the specific implementation process, when the processor 320 executes the program 311, any method and step in the first embodiment can also be implemented.
[0215] Embodiment 4
[0216] Based on the same inventive concept as the distance calculation method based on area division in the aforementioned embodiment, Figure 4 As shown, a computer readable storage medium 400 stores a computer program 411, which implements the following steps when executed by a processor:
[0217] Obtain the coordinates of the boundary position point of the specific area to obtain a first result; based on the first result and the target preset unit, divide the specific area into regions to obtain a second result, where the second result is a region including multiple sub-regions; determine the coordinates of the region center position of each sub-region to obtain a third result; based on the third result, obtain the distance from the region center position of each sub-region to each preset target point to obtain a fourth result; obtain a distance request from the client, where the distance request includes the user's current position and the target point, where the target point is one of the preset target points; determine the sub-region where the current position is located in the second result to obtain a fifth result; based on the fourth result and the fifth result, determine the distance between the current position and the target point, and send it to the client.
[0218] In the specific implementation process, when the computer program 411 is executed by the processor, any method step in the first embodiment can be implemented.
[0219] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.
[0220] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.
Claims
1. A distance calculation method based on region division, characterized in that: Applied in a server, the server is connected to a client, and the method comprises: Obtaining the coordinates of the boundary position points of the specific area to obtain a first result; Based on the first result and the target preset unit, the specific area is divided into regions to obtain a second result, where the second result is a region including a plurality of sub-regions; Determine the coordinates of the center position of each sub-region to obtain a third result; Based on the third result, the distance from the center position of each sub-region to each preset target point is obtained to obtain and store a fourth result; Obtaining a distance request from the client, the distance request including the user's current location and a target point, the target point being one of the preset target points; Determine the sub-region where the current position is located in the second result, to obtain a fifth result; The stored fourth result and the fifth result are called to determine the distance between the current position and the target point, and the distance is sent to the client.
2. The distance calculation method based on area division according to claim 1, characterized in that: The step of dividing the specific area based on the first result and the target preset unit to obtain the second result includes: Based on the first result, the specific area is divided into N levels to obtain a sixth result, where the sixth result includes the areas obtained after each level of regional division; Based on the target preset unit, the specific area is divided into an N+1th level area to obtain the second result, where the second result is an area including a plurality of N+1th sub-areas.
3. The distance calculation method based on area division as claimed in claim 2, characterized in that: Based on the first result, the specific area is divided into N levels to obtain a sixth result, wherein the sixth result includes areas obtained after each level of regional division, including: According to the first preset unit and the first result, the specific area is divided into a first level area to obtain a first area, where the first area is an area including a plurality of first sub-areas; According to a second preset unit, performing a second-level region division on each of the first sub-regions in the first region to obtain a second region, where the second region is a region including a plurality of second sub-regions; And so on, until each N-1th sub-region of the N-1th region is divided into the Nth level according to the Nth preset unit to obtain the Nth region, where the Nth region is a region including multiple Nth sub-regions, wherein the sixth result includes each region from the first region to the Nth region.
4. The distance calculation method based on area division as claimed in claim 3, characterized in that: Based on the target preset unit, each of the Nth sub-regions is divided into regions to obtain the second result, where the second result is a region including multiple N+1th sub-regions, including: Based on the target preset unit, each of the Nth sub-regions in the Nth region is divided into an N+1th level region to obtain an N+1th region, and the N+1th region is the second result.
5. The distance calculation method based on area division as claimed in claim 4, characterized in that: Before determining the sub-region where the current position is located in the second result to obtain the fifth result, the method further includes: The coordinates of the region center position of each i-th sub-region in the i-th region are obtained, where i is a positive integer from 1 to N.
6. The distance calculation method based on area division as claimed in claim 5, characterized in that: The determining the sub-region where the current position is located in the second result to obtain a fifth result includes: Obtaining the coordinates of the center position of each of the i-th sub-regions within the target sub-region where the i-th region is located, the target sub-region being the i-1th sub-region where the current position is located within the i-1th region; Based on the coordinates of the region center position of each of the i-th sub-regions in the target sub-region, determining the distances between the current position and the region center position of each of the i-th sub-regions in the target sub-region, to obtain a seventh result; Based on the seventh result, determine the i-th sub-region where the current position is located in the i-th region, where i is a positive integer from 1 to N in sequence, until it is determined that the current position is in the N-th sub-region of the N+1-th region, and when i is 1, the target sub-region is the specific region.
7. The distance calculation method based on area division as claimed in claim 2, characterized in that: The step of determining the coordinates of the center position of each sub-region to obtain a third result includes: Determine the coordinates of the center position of each of the N+1th sub-regions to obtain the third result; Based on the third result, obtaining the distance from the area center position of each sub-area to each preset target point to obtain a fourth result includes: Based on the third result, the distance from the area center position of each of the N+1th sub-areas to each preset target point is obtained to obtain the fourth result.
8. A distance calculation device based on area division, characterized in that: Applied in a server, the server is connected to a client, and the device comprises: A first acquisition unit, used to acquire the coordinates of a boundary position point of a specific area to obtain a first result; a dividing unit, configured to divide the specific area into regions according to the first result and a target preset unit, to obtain a second result, wherein the second result is a region including a plurality of sub-regions; A first determining unit, used to determine the coordinates of the region center position of each of the sub-regions to obtain a third result; A second acquisition unit is used to acquire the distance from the center position of each sub-region to each preset target point according to the third result, obtain a fourth result and store it; A third acquisition unit is used to acquire a distance request from the client, wherein the distance request includes a current position of the user and a target point, and the target point is one of the preset target points; A second determining unit, configured to determine a sub-region where the current position is located in the second result, to obtain a fifth result; The third determining unit is used to call the stored fourth result and the fifth result, determine the distance between the current position and the target point, and send the distance to the client.
9. An electronic device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor can implement the method steps as claimed in any one of claims 1 to 7 when executing the program.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: include: When the program is executed by a processor, the method steps described in any one of claims 1 to 7 can be implemented.
