CN117076846A - Distance calculation method, system, equipment and storage medium - Google Patents
Distance calculation method, system, equipment and storage medium Download PDFInfo
- Publication number
- CN117076846A CN117076846A CN202311128860.9A CN202311128860A CN117076846A CN 117076846 A CN117076846 A CN 117076846A CN 202311128860 A CN202311128860 A CN 202311128860A CN 117076846 A CN117076846 A CN 117076846A
- Authority
- CN
- China
- Prior art keywords
- distance
- target
- formula
- merchant
- coordinates
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F17/00—Digital computing or data processing equipment or methods, specially adapted for specific functions
- G06F17/10—Complex mathematical operations
- G06F17/18—Complex mathematical operations for evaluating statistical data, e.g. average values, frequency distributions, probability functions, regression analysis
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/21—Design, administration or maintenance of databases
- G06F16/211—Schema design and management
- G06F16/212—Schema design and management with details for data modelling support
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/29—Geographical information databases
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/95—Retrieval from the web
- G06F16/953—Querying, e.g. by the use of web search engines
- G06F16/9537—Spatial or temporal dependent retrieval, e.g. spatiotemporal queries
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Databases & Information Systems (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Data Mining & Analysis (AREA)
- General Engineering & Computer Science (AREA)
- Mathematical Optimization (AREA)
- Pure & Applied Mathematics (AREA)
- Mathematical Analysis (AREA)
- Computational Mathematics (AREA)
- Mathematical Physics (AREA)
- Algebra (AREA)
- Probability & Statistics with Applications (AREA)
- Evolutionary Biology (AREA)
- Operations Research (AREA)
- Bioinformatics & Computational Biology (AREA)
- Software Systems (AREA)
- Bioinformatics & Cheminformatics (AREA)
- Life Sciences & Earth Sciences (AREA)
- Remote Sensing (AREA)
- Management, Administration, Business Operations System, And Electronic Commerce (AREA)
Abstract
The application provides a distance calculating method, a system, equipment and a storage medium, which relate to the technical field of information processing, wherein the distance calculating method comprises the following steps: acquiring point coordinates of a target point and acquiring merchant information of each target merchant in a target city where the target point is located, wherein the merchant information comprises: commercial tenant coordinates; establishing a distance formula between the point coordinates and target coordinates in each merchant coordinate based on a rectangular diagonal formula; training the distance formula in a preset fitting range through a polynomial curve fitting algorithm to obtain a trained fitting formula; and inputting the point coordinates and the merchant coordinates into the fitting formula for calculation to obtain the distance between the target point and each target merchant. The distance calculation method can simplify the formula of distance calculation, and reduce the complexity of calculation under the condition of not affecting the calculation precision, thereby reducing the time of distance calculation and the CPU occupation rate during calculation.
Description
Technical Field
The present application relates to the field of information processing technologies, and in particular, to a distance calculating method, a distance calculating system, a distance calculating device, and a distance calculating storage medium.
Background
In a life recommendation system, scenes such as food recommendation generally take the distance between a store and a user as an important feature, a popular city usually has tens of thousands of stores, and a large number of distance calculations occupy a CPU (Central Processing Unit ) when the distance calculation is performed for each user for one recommendation.
The main flow of the calculation of the distance between two points on the earth surface usually adopts a Haversine (semi-normal) formula, in which the earth is regarded as a sphere to perform the distance calculation, a large number of trigonometric functions are used, the calculation is more accurate, but the calculation speed of the trigonometric functions is slower, a large number of CPUs are occupied when the calculation is performed in a large number, and the time consumption is longer.
Disclosure of Invention
The application mainly aims to provide a distance calculating method, a distance calculating system, distance calculating equipment and a distance calculating storage medium, and aims to solve the problems that the traditional distance calculating method is complex in calculation, long in time consumption and high in CPU occupancy rate.
In order to achieve the above object, the present application provides a distance calculating method, including:
acquiring point coordinates of a target point and acquiring merchant information of each target merchant in a target city where the target point is located, wherein the merchant information comprises: commercial tenant coordinates;
Establishing a distance formula between the point coordinates and target coordinates in each merchant coordinate based on a rectangular diagonal formula;
training the distance formula in a preset fitting range through a polynomial curve fitting algorithm to obtain a trained fitting formula;
and inputting the point coordinates and the merchant coordinates into the fitting formula for calculation to obtain the distance between the target point and each target merchant.
Optionally, in a possible embodiment, the point coordinates include: a first longitude and a first latitude, the target coordinates comprising: a second longitude and a second latitude;
the step of establishing a distance formula between the point coordinates and target coordinates in the merchant coordinates based on a rectangular diagonal formula comprises the following steps:
calculating a longitude difference between the first longitude and the second longitude, and calculating an average latitude of the first latitude and the second latitude;
calculating an east-west distance between the point coordinates and the target coordinates according to the longitude difference and the average latitude;
calculating a north-south distance between the point coordinates and the target coordinates according to the altitude difference between the first latitude and the second latitude;
Substituting the east-west distance and the north-south distance into the rectangular diagonal formula to establish a distance formula between the point coordinates and the target coordinates.
Optionally, in a possible embodiment, the distance formula includes a trigonometric function term;
the step of training the distance formula in a preset fitting range through a polynomial curve fitting algorithm comprises the following steps:
average cutting out a preset number of sampling points in a preset fitting range;
training each sampling point through a polynomial curve fitting algorithm to obtain a polynomial function fitted with the trigonometric function term;
and replacing trigonometric function terms in the distance formula with the polynomial function to obtain a fitting formula.
Optionally, in a feasible embodiment, the step of obtaining merchant information of each target merchant in the target city where the target point is located includes:
determining a target city where the target point is located according to the point coordinates;
judging whether merchant information of each target merchant in the target city in the memory cache exists or not based on the acquired distance request instruction, and obtaining a judging result;
and if the judging result is that the commercial tenant information exists, acquiring the commercial tenant information from the memory cache.
Optionally, in a possible embodiment, after the step of obtaining a result of the judging, the method further includes:
if the judging result is that the business does not exist, acquiring all effective cities of all the owned merchants through a preset remote dictionary server;
judging whether each effective city contains the target city or not;
and if the target city is contained in each effective city, acquiring the merchant information through the remote dictionary server.
Optionally, in a possible embodiment, after the step of obtaining each piece of merchant information through the remote dictionary service, the method further includes:
removing the businesses stopping operation in each target business through the operation information in each business information to obtain the effective information of each effective business in the target city;
and storing each piece of effective information into the memory cache.
Optionally, in a possible embodiment, before the step of acquiring the merchant information of each target merchant in the target city where the target point is located, the method further includes:
synchronizing data information of all merchants in all cities to a preset elastic search database and a preset remote dictionary server through an external interface, wherein the data information comprises identity information of merchants in all places in each city;
Taking the names of the cities as city key values of the local merchants of the cities, and splicing and writing the identity information in the elastic search database into the remote dictionary server;
and splicing and writing the effective names of the effective cities with the merchants in each city into the remote dictionary server through a preset fixed key value so as to finish the establishment of the remote dictionary server.
In addition, in order to achieve the above object, the present application further provides a distance computing system, which is a virtual system, comprising:
the information acquisition module is used for acquiring point coordinates of a target point and acquiring merchant information of each target merchant in a target city where the target point is located, wherein the merchant information comprises: commercial tenant coordinates;
the formula establishing module is used for establishing a distance formula between the point coordinates and target coordinates in the merchant coordinates based on a rectangular diagonal formula;
the formula training module is used for training the distance formula in a preset fitting range through a polynomial curve fitting algorithm so as to obtain a trained fitting formula;
And the distance calculation module is used for inputting the point coordinates and the merchant coordinates into the fitting formula for calculation so as to obtain the distance between the target point and each target merchant.
In addition, to achieve the above object, the present application also provides a distance calculating apparatus including: the distance calculation device comprises a memory, a processor and a distance calculation program which is stored in the memory and can run on the processor, wherein the distance calculation program realizes the steps of the distance calculation method when being executed by the processor.
The present application also provides a computer storage medium having a distance calculation program stored thereon, which when executed by a processor, implements the steps of the distance calculation method as described above.
The application provides a distance calculating method, a system, equipment and a storage medium, wherein the distance calculating method comprises the following steps: acquiring point coordinates of a target point and acquiring merchant information of each target merchant in a target city where the target point is located, wherein the merchant information comprises: commercial tenant coordinates; establishing a distance formula between the point coordinates and target coordinates in each merchant coordinate based on a rectangular diagonal formula; training the distance formula in a preset fitting range through a polynomial curve fitting algorithm to obtain a trained fitting formula; and inputting the point coordinates and the merchant coordinates into the fitting formula for calculation to obtain the distance between the target point and each target merchant.
Compared with the technical means of calculating the distance by adopting a Haverine formula, the distance calculation method of the application firstly obtains the point coordinates of the target point where the user is located or the target point where the user wants to inquire and the merchant coordinates of all merchants in the city where the user is located, then establishes a distance formula between two points based on a rectangular diagonal formula, trains the distance formula in a preset fitting range by a polynomial curve fitting algorithm, eliminates a trigonometric function in the distance formula to obtain a fitting formula, and finally substitutes the point coordinates of each merchant and the point coordinates of the user into the fitting formula to calculate the distance between each merchant and the target point.
In this way, compared with the traditional method for calculating the distance by adopting the Haverine formula, the distance calculation method of the application simplifies the distance formula between two points by the diagonal formula and replaces the trigonometric function in the distance formula by the polynomial curve fitting algorithm by the principle that the distance between two points is relatively close to the whole earth in the same city, thereby reducing the calculation complexity without affecting the calculation accuracy and reducing the time of distance calculation and CPU occupation rate during calculation.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the application and together with the description, serve to explain the principles of the application.
In order to more clearly illustrate the embodiments of the application or the technical solutions of the prior art, the drawings which are used in the description of the embodiments or the prior art will be briefly described, and it will be obvious to a person skilled in the art that other drawings can be obtained from these drawings without inventive effort.
FIG. 1 is a schematic diagram of a distance computing device in a device hardware operating environment according to an embodiment of the present application;
FIG. 2 is a schematic diagram of an implementation flow of an embodiment of a distance calculation method according to the present application;
FIG. 3 is a schematic diagram illustrating an implementation flow of an embodiment of a distance calculation method according to the present application;
FIG. 4 is a schematic flow chart illustrating an embodiment of a distance calculating method according to the present application;
fig. 5 is a schematic diagram of functional modules of a distance calculating system according to an embodiment of the present application.
The achievement of the objects, functional features and advantages of the present application will be further described with reference to the accompanying drawings, in conjunction with the embodiments.
Detailed Description
It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the application.
It should be noted that, if there is a description of "first", "second", etc. in the embodiments of the present invention, the description of "first", "second", etc. is only for descriptive purposes, and is not to be construed as indicating or implying relative importance or implying that the number of technical features indicated is indicated. Thus, a feature defining "a first" or "a second" may explicitly or implicitly include at least one such feature. In addition, the technical solutions of the embodiments may be combined with each other, but it is necessary to base that the technical solutions can be realized by those skilled in the art, and when the technical solutions are contradictory or cannot be realized, the combination of the technical solutions should be considered to be absent and not within the scope of protection claimed in the present invention.
In the living recommendation system, scenes such as food recommendation generally take the distance between a store and a user as an important feature, and there are often tens of thousands of stores in a popular city, and a large amount of distance calculation occupies a CPU (Central Processing Unit ) in that tens of thousands of distance calculation are performed for each user to make a recommendation.
The main flow of the calculation of the distance between two points on the earth surface usually adopts a Haversine (semi-normal) formula, in which the earth is regarded as a sphere to perform the distance calculation, a large number of trigonometric functions are used, the calculation is more accurate, but the calculation speed of the trigonometric functions is slower, a large number of CPUs are occupied when the calculation is performed in a large number, and the time consumption is longer.
In view of the above problems, the present application provides a distance calculating method, a system, a device, and a storage medium, where the distance calculating method includes: acquiring point coordinates of a target point and acquiring merchant information of each target merchant in a target city where the target point is located, wherein the merchant information comprises: commercial tenant coordinates; establishing a distance formula between the point coordinates and target coordinates in each merchant coordinate based on a rectangular diagonal formula; training the distance formula in a preset fitting range through a polynomial curve fitting algorithm to obtain a trained fitting formula; and inputting the point coordinates and the merchant coordinates into the fitting formula for calculation to obtain the distance between the target point and each target merchant.
Compared with the technical means of calculating the distance by adopting a Haverine formula, the distance calculation method of the application firstly obtains the point coordinates of the target point where the user is located or the target point where the user wants to inquire and the merchant coordinates of all merchants in the city where the user is located, then establishes a distance formula between two points based on a rectangular diagonal formula, trains the distance formula in a preset fitting range by a polynomial curve fitting algorithm, eliminates a trigonometric function in the distance formula to obtain a fitting formula, and finally substitutes the point coordinates of each merchant and the point coordinates of the user into the fitting formula to calculate the distance between each merchant and the target point.
In this way, compared with the traditional method for calculating the distance by adopting the Haverine formula, the distance calculation method of the application simplifies the distance formula between two points by the diagonal formula and replaces the trigonometric function in the distance formula by the polynomial curve fitting algorithm by the principle that the distance between two points is relatively close to the whole earth in the same city, thereby reducing the calculation complexity without affecting the calculation accuracy and reducing the time of distance calculation and CPU occupation rate during calculation.
The following description of the embodiments of the present application will be made clearly and fully with reference to the accompanying drawings, in which it is evident that the embodiments described are only some, but not all embodiments of the application. Based on the embodiments of the present application, various other embodiments may be made by those of ordinary skill in the art without making any inventive effort, which are within the scope of the present application.
Referring to fig. 1, fig. 1 is a schematic diagram of a distance computing device in a device hardware operating environment according to an embodiment of the present application.
The terminal equipment in the embodiment of the application can be a back-end server.
As shown in fig. 1, the distance calculating apparatus may include: a processor 1001, such as a CPU, memory 1005, and a communication bus 1002. Wherein a communication bus 1002 is used to enable connected communication between the processor 1001 and a memory 1005. The memory 1005 may be a high-speed RAM memory or a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may also optionally be a storage device separate from the processor 1001 described above.
Optionally, the distance computing device may also include a user interface 1003, a network interface 1004, a camera, RF (Radio Frequency) circuitry, sensors, audio circuitry, wiFi modules, and the like. The user interface may comprise a Display, an input sub-module such as a Keyboard (Keyboard), and optionally may comprise a standard wired interface, a wireless interface. The network interface may optionally include a standard wired interface, a wireless interface (e.g., WIFI interface).
Those skilled in the art will appreciate that the distance computing device structure shown in fig. 1 is not limiting of the distance computing device and may include more or fewer components than shown, or may combine certain components, or a different arrangement of components.
As shown in fig. 1, an operating system, a network communication module, and a distance calculation program may be included in the memory 1005, which is a type of computer storage medium. An operating system is a program that manages and controls the distance computing device hardware and software resources, supporting the execution of distance computing programs, as well as other software and/or programs. The network communication module is used to enable communication between components within the memory 1005 and with other hardware and software in the distance computing system.
In the distance calculation device shown in fig. 1, the processor 1001 is configured to execute a distance calculation program stored in the memory 1005, and perform the following operations:
acquiring point coordinates of a target point and acquiring merchant information of each target merchant in a target city where the target point is located, wherein the merchant information comprises: commercial tenant coordinates;
establishing a distance formula between the point coordinates and target coordinates in each merchant coordinate based on a rectangular diagonal formula;
training the distance formula in a preset fitting range through a polynomial curve fitting algorithm to obtain a trained fitting formula;
and inputting the point coordinates and the merchant coordinates into the fitting formula for calculation to obtain the distance between the target point and each target merchant.
Further, the processor 1001 may call a distance calculation program stored in the memory 1005, and further perform the following operations:
calculating a longitude difference between the first longitude and the second longitude, and calculating an average latitude of the first latitude and the second latitude;
calculating an east-west distance between the point coordinates and the target coordinates according to the longitude difference and the average latitude;
calculating a north-south distance between the point coordinates and the target coordinates according to the altitude difference between the first latitude and the second latitude;
substituting the east-west distance and the north-south distance into the rectangular diagonal formula to establish a distance formula between the point coordinates and the target coordinates.
Further, in a possible embodiment, a preset number of sampling points are evenly cut out in a preset fitting range;
training each sampling point through a polynomial curve fitting algorithm to obtain a polynomial function fitted with the trigonometric function term;
and replacing trigonometric function terms in the distance formula with the polynomial function to obtain a fitting formula.
Further, in a possible embodiment, determining a target city in which the target point is located according to the point coordinates;
Judging whether merchant information of each target merchant in the target city in the memory cache exists or not based on the acquired distance request instruction, and obtaining a judging result;
and if the judging result is that the commercial tenant information exists, acquiring the commercial tenant information from the memory cache.
Further, in a feasible embodiment, if the judging result is that the judging result does not exist, acquiring all effective cities with merchants through a preset remote dictionary server;
judging whether each effective city contains the target city or not;
and if the target city is contained in each effective city, acquiring the merchant information through the remote dictionary server.
Further, in a feasible embodiment, the merchants stopping operation in the target merchants are removed through the operation information in the merchant information, so that the effective information of each effective merchant in the target city is obtained;
and storing each piece of effective information into the memory cache.
Further, in a possible embodiment, synchronizing data information of all merchants in all cities to a preset elastic search database and a preset remote dictionary server through an external interface, wherein the data information comprises identity information of merchants in all places in each city;
Taking the names of the cities as city key values of the local merchants of the cities, and splicing and writing the identity information in the elastic search database into the remote dictionary server;
and splicing and writing the effective names of the effective cities with the merchants in each city into the remote dictionary server through a preset fixed key value so as to finish the establishment of the remote dictionary server.
An embodiment of the present application provides a distance calculating method, in a first embodiment of the distance calculating method of the present application, referring to fig. 2, the distance calculating method includes:
step S10, acquiring point coordinates of a target point and acquiring merchant information of each target merchant in a target city where the target point is located, wherein the merchant information comprises: commercial tenant coordinates;
in this embodiment, the obtained merchant information of each merchant includes various information of each merchant, where the merchant information of each merchant includes coordinates of the merchant.
In this embodiment, when the user searches for a nearby merchant at the front end or needs the back end to recommend a nearby merchant, the back end uses a point set by the user or a point where the user is located as a target point, acquires point coordinates of the target point, and acquires merchant coordinates of each merchant in the city where the user is located.
Step S20, establishing a distance formula between the point coordinates and target coordinates in the merchant coordinates based on a rectangular diagonal formula;
in this embodiment, since the merchant and the user to be recommended are located in the same city, the distance between the two points is relatively close to the whole earth, so the whole city can be regarded as a plane, and the warp and the weft can be regarded as straight lines perpendicular to each other, thereby calculating the distance between the two points.
When the rectangular diagonal formula is formed by summing the square of the rectangular length and the square of the rectangular width, and the warp and the weft are regarded as straight lines perpendicular to each other, the distance formula between the two points may be established by the rectangular diagonal formula by regarding the two points as points of the diagonal of the rectangle with the warp and the weft as references.
Further, in a possible embodiment, the point coordinates include: a first longitude and a first latitude, the target coordinates comprising: a second longitude and a second latitude;
the step S20 of establishing a distance formula between the point coordinates and the target coordinates in the merchant coordinates based on the rectangular diagonal formula includes:
step S201 of calculating a longitude difference between the first longitude and the second longitude, and calculating an average latitude of the first latitude and the second latitude;
Step S202, calculating the east-west distance between the point coordinates and the target coordinates according to the longitude difference and the average latitude;
step S203, calculating the north-south distance between the point coordinates and the target coordinates according to the latitude difference between the first latitude and the second latitude;
step S204, substituting the east-west distance and the north-south distance into the rectangular diagonal formula to establish a distance formula between the point coordinates and the target coordinates.
In this embodiment, however, since the distance between two points in the same city is relatively short, the distance between two points is calculated as the distance between two points in the plane.
In this embodiment, the longitude difference and the average latitude between the point coordinates and the target coordinates are calculated first, then the east-west distance between the point coordinates and the target coordinates is calculated through the longitude difference and the average latitude, then the north-south distance between the point coordinates and the target coordinates is calculated through the latitude difference between the point coordinates and the target coordinates, and finally the east-west distance and the north-south distance are substituted into a rectangular diagonal formula to obtain the distance formula between the point coordinates and the target coordinates.
Specifically, the distance formula is as follows:
Wherein dx is the east-west distance between the point coordinates and the target coordinates, lon1 is the first longitude of the point coordinates, lat1 is the first latitude of the point coordinates, R is the earth radius, dy is the north-south distance between the point coordinates and the target coordinates, lon2 is the second longitude of the target coordinates, lat2 is the second latitude of the target coordinates, and D is the distance between the two points.
In order to verify the superiority of the distance formula compared with the haverine formula, 2000 times 2000 points are taken in the ranges of 100, 1000, 10000 and 100000 meters around a plurality of target points respectively, the distance between the target point and the selected point is calculated by using the haverine formula and the distance formula respectively, and the maximum difference of the distances calculated under the two formulas is counted, wherein the maximum difference is shown in the table one:
maximum difference between calculated results of table-distance formula and Haverine formula
As shown in table one, four points of Shenzhen, shanghai, beijing and Harbin are selected respectively, the distance difference value calculated by two formulas in four ranges is calculated respectively, the difference unit is meter, the distance difference calculated by the two formulas is very small and can be ignored, and therefore, the calculation accuracy of the distance formulas meets the requirement.
In the verification process, the time length required by the two formulas when calculating 1, 10 and 100 ten thousand commercial shops is counted simultaneously, and the counting result is as follows:
time consumption comparison of calculation of table two distance formula and Haverine formula
As shown in table two, the distance formula established by using the diagonal of the rectangle consumes much less time in calculation than is required by using the haverine formula.
Step S30, training the distance formula in a preset fitting range through a polynomial curve fitting algorithm to obtain a trained fitting formula;
in this embodiment, although the distance formula can greatly reduce the time consumption of calculation under the condition of ensuring the calculation accuracy, the distance formula still includes a trigonometric function, and the calculation complexity is higher, so that a polynomial curve fitting algorithm is adopted to train the distance formula so as to obtain a fitting formula composed of polynomials, thereby reducing the calculation complexity.
Further, in a possible embodiment, the distance formula includes a trigonometric function term;
in the step S30, the step of training the distance formula in a preset fitting range through a polynomial curve fitting algorithm includes:
Step S301, a preset number of sampling points are evenly cut out in a preset fitting range;
step S302, training each sampling point through a polynomial curve fitting algorithm to obtain a polynomial function fitted with the trigonometric function item;
and step S303, replacing trigonometric function terms in the distance formula with the polynomial function to obtain a fitting formula.
In this embodiment, as can be seen from the above distance formula, the distance formula includes a trigonometric function, and the cosine function can be fitted by a tetrad function, so as to reduce the complexity of calculation. When fitting training is carried out, the latitude range of most areas in China is 18-50 degrees in north latitude, so that the fitting range is 18-50 degrees, sampling points of 100 cos functions are cut out in average in the range to serve as a training set, each coefficient of a polynomial is obtained by using a polynomial curve fitting algorithm, and then a trigonometric function in a distance formula is replaced by a polynomial function obtained by fitting, so that a fitting formula can be obtained.
In addition, if the method needs to be applied to other countries, the training can be performed again according to the dimension range of the target country to obtain each coefficient of the polynomial.
Specifically, the fitting formula is as follows:
cosAvgLat=(3.2000E-9)avgLat 4 +(5.8161E-8)avgLat 3 -(1.5440E-4)avgLat 2 +(3.4584E-5)avgLat+0.9998
where avgLat is the average latitude between the point coordinates and the target coordinates, 3.2000E-9, 5.8161E-8, - (1.5440E-4), 3.4584E-5, and 0.9998 are the various polynomial coefficients trained by the polynomial curve fitting algorithm.
Similarly, in order to verify the superiority of the fitting formula compared with the distance formula and the Haversine formula, in the ranges of 100, 1000, 10000 and 100000 meters around a plurality of target points, 2000 times 2000 points are taken, the distance between the target point and the selected point is calculated by using the Haversine formula and the distance formula, and the maximum difference of the distances calculated by the two formulas is calculated, wherein the maximum difference is shown in table three:
maximum difference between the table three fitting formula and the calculated results of the distance formula and Haverine formula
As shown in table three, four points of Shenzhen, shanghai, beijing and Harbin are selected respectively, the maximum distance difference between the distances calculated by the fitting formula and the other two formulas in four ranges is calculated respectively, the difference unit is meter, the distance difference calculated by the fitting formula and the Haverine formula is very small and can be ignored, and therefore, the calculation accuracy of the distance formula meets the requirement.
In the verification process, the time length required by the statistical fitting formula and the distance formula when calculating 1, 10 and 100 ten thousand commercial shops is calculated, and the statistical result is as follows:
time-consuming comparison of table four fitting formula, distance formula and haverine formula
As shown in table four, the length of time that the trained fitting formula spends in the calculation is the shortest of the three formulas.
And S40, inputting the point coordinates and the merchant coordinates into the fitting formula for calculation to obtain the distance between the target point and each target merchant.
In this embodiment, the fitting formula obtained through fitting training has good performance in terms of calculation accuracy and time consumption, so when the distances of all merchants are required to be calculated, the distances between all merchants and the target point set by the user can be calculated by substituting the coordinates of all merchants and the point coordinates of the user.
In addition, the calculation process can be performed in a Java virtual machine, so that the resources of a database are saved.
In this embodiment, compared with the technical means of calculating the distance by using the haverine formula, the distance calculation method of the present application obtains the point coordinates of the target point where the user is located or the target point where the user wants to query and the merchant coordinates of all merchants in the city where the user is located, then establishes a distance formula between two points based on a rectangular diagonal formula, trains the distance formula in a preset fitting range by using a polynomial curve fitting algorithm, eliminates a trigonometric function in the distance formula to obtain a fitting formula, and finally substitutes each merchant coordinate and the point coordinates of the user into the fitting formula to calculate the distance between each merchant and the target point.
In this way, compared with the traditional method for calculating the distance by adopting the Haverine formula, the distance calculation method of the application simplifies the distance formula between two points by the diagonal formula and replaces the trigonometric function in the distance formula by the polynomial curve fitting algorithm by the principle that the distance between two points is relatively close to the whole earth in the same city, thereby reducing the calculation complexity without affecting the calculation accuracy and reducing the time of distance calculation and CPU occupation rate during calculation.
Further, based on the first embodiment of the distance calculation method of the present application described above, a second embodiment of the distance calculation method of the present application is proposed.
In a second embodiment of the distance calculating method of the present application, in the step S10, the step of obtaining the merchant information of each target merchant in the target city where the target point is located includes:
step S101, determining a target city where the target point is located according to the point coordinates;
step S102, judging whether merchant information of each target merchant in the target city in a memory cache exists or not based on the acquired distance request instruction, and obtaining a judging result;
Step S103, if the determination result is that the information exists, acquiring each piece of merchant information from the memory cache.
In this embodiment, the target city to which the point coordinates belong is determined according to the point coordinates of the target points set by the user, and then, after the user sends a distance request instruction at the front end, the back end server detects whether the merchant information of the target city in the memory cache exists or not in response to the instruction, and if so, the information of each merchant is directly obtained from the memory cache.
Further, in a possible embodiment, after the step of obtaining the determination result in the step S102, the method further includes:
step S104, if the judging result is that the business does not exist, acquiring effective cities of all the owned merchants through a preset remote dictionary server;
step S105, determining whether each valid city includes the target city;
and step S106, if the effective cities contain the target cities, acquiring the merchant information through the remote dictionary server.
It should be noted that the remote dictionary server is an open source log-type, key-Value database written in ANSI C language, supporting network, and capable of being based on memory and persistent, and provides API of multiple languages.
In this embodiment, the back-end server is connected to a remote dictionary server, where identity information and data information of all merchants in each city are stored correspondingly according to names of cities as key values.
If the memory cache is judged to have no merchant information of the target city, acquiring effective cities with more merchants from the remote dictionary server, judging whether the target city is in the effective city, if not, returning to be empty, and if so, acquiring merchant information of all merchants of the target city through the remote dictionary server.
Further, in the step S106, after the step of obtaining the merchant information through the remote dictionary service, the method further includes:
step S107, removing the businesses which have stopped operating in the target businesses through the operation information in the business information so as to obtain the effective information of each effective business in the target city;
step S108, storing each effective information into the memory cache.
In this embodiment, after the merchant information of all merchants in the target city is obtained, the merchants that have stopped business are removed according to the operation information in the merchant information, only the effective merchants that operate normally remain, and then the information of the effective merchants are stored in the memory cache for subsequent call.
Specifically, referring to fig. 3, fig. 3 is a schematic flow chart illustrating an implementation of a distance calculating method according to an embodiment of the application. As shown in fig. 3, when a user needs a back end to recommend a merchant, an interface request is sent through the front end, after receiving the request, a back end server obtains store information of a city where the user is located, firstly judges whether store information of the city where the user is located is stored in a local cache, if yes, directly obtains store information from the local cache, if no, inquires all cities with stores in redis, then judges whether the target city where the user is located is contained, if no, returns a null value, if yes, inquires identity Information (ID) of all stores in the city where the user is located in redis by taking the target city as a key value, inquires store information of all stores through each ID, rejects the stores in the local cache after the stores are stopped, then calculates distances in a Java virtual machine, calculates recommended points of all merchants through the existing recommended point calculation method in combination with the calculated distances, and finally returns the recommended points to a value recommended store list.
Compared with the technical means of distance calculation in an elastic search database in the prior art, the distance calculation method stores merchant information of a target city in a cache, calls data from the cache, saves bandwidth occupation, does not need networking call, is more stable, calculates in a Java virtual machine, and solves the problem that the traditional algorithm is too dependent on the elastic search database.
Further, based on the first and second embodiments of the distance calculation method of the present application described above, a third embodiment of the distance calculation method of the present application is proposed.
In a third embodiment of the distance calculating method of the present application, before the step of obtaining the merchant information of each target merchant in the target city where the target point is located in the step S10, the method further includes:
step A10, synchronizing data information of all merchants in all cities to a preset elastic search database and a preset remote dictionary server through an external interface, wherein the data information comprises identity information of merchants in all places in each city;
step A20, using the names of the cities as city key values of the local merchants of the cities, and splicing and writing the identity information in the elastic search database into the remote dictionary server;
and step A30, splicing and writing the effective names of the effective cities with the merchants in each city into the remote dictionary server through a preset fixed key value so as to finish the establishment of the remote dictionary server.
In this embodiment, before the backend accesses the client, a remote dictionary server needs to be established first, and the data of the city and the merchant are correspondingly stored in the remote dictionary server.
Firstly synchronizing all merchant data of all cities to a preset elastic search database and a preset remote dictionary server through an external interface, then taking all merchant information out of the elastic search database at regular time, aggregating all merchants of each city by taking the cities as dimensions, splicing and writing IDs of each city into a redis server by taking names of the cities as key values, counting all effective cities with the merchants, setting a fixed key value, splicing and writing the names of all effective cities into the redis server, and completing establishment of the redis server.
Specifically, referring to fig. 4, fig. 4 is a schematic flow chart illustrating an implementation of a distance calculating method according to an embodiment of the application. As shown in fig. 4, when the redis server is pre-established, firstly, synchronizing information of all stores into the ES database and the redis server in a full-volume synchronization and incremental synchronization mode through an external interface, then setting a timing task, aggregating all merchant information of the cities in the ES database by taking the cities as dimensions every thirty minutes, writing the merchant ID of each city into the redis server by taking the names of the cities as key values, aggregating all cities with the merchants, and splicing and writing the names of the cities with the merchants into the redis server by fixed key values to establish the redis server.
Compared with the traditional construction of an ES database, the method has the advantages that extra bandwidth is consumed in the process of inquiring and calculating in the ES database, and the network is connected to each inquiry, so that delay and instability are increased.
In addition, referring to fig. 5, fig. 5 is a schematic functional block diagram of a distance computing system according to the present application, and the present application further provides a distance computing system, where the distance computing system includes:
an information obtaining module 10, configured to obtain point coordinates of a target point, and obtain merchant information of each target merchant in a target city where the target point is located, where the merchant information includes: commercial tenant coordinates;
a formula creation module 20, configured to create a distance formula between the point coordinates and the target coordinates in each of the merchant coordinates based on a rectangular diagonal formula;
the formula training module 30 is configured to train the distance formula in a preset fitting range through a polynomial curve fitting algorithm, so as to obtain a trained fitting formula;
and the distance calculating module 40 is configured to input the point coordinates and the merchant coordinates into the fitting formula for calculation, so as to obtain the distance between the target point and each target merchant.
Optionally, the formula creation module includes:
a calculation unit configured to calculate a longitude difference between the first longitude and the second longitude, and calculate an average latitude of the first latitude and the second latitude; calculating an east-west distance between the point coordinates and the target coordinates according to the longitude difference and the average latitude; calculating a north-south distance between the point coordinates and the target coordinates according to the altitude difference between the first latitude and the second latitude; substituting the east-west distance and the north-south distance into the rectangular diagonal formula to establish a distance formula between the point coordinates and the target coordinates.
Optionally, the formula training module includes:
the training unit is used for evenly dividing a preset number of sampling points in a preset fitting range; training each sampling point through a polynomial curve fitting algorithm to obtain a polynomial function fitted with the trigonometric function term; and replacing trigonometric function terms in the distance formula with the polynomial function to obtain a fitting formula.
Optionally, the information acquisition module includes:
the cache information acquisition unit is used for determining a target city where the target point is located according to the point coordinates; judging whether merchant information of each target merchant in the target city in the memory cache exists or not based on the acquired distance request instruction, and obtaining a judging result; and if the judging result is that the commercial tenant information exists, acquiring the commercial tenant information from the memory cache.
Optionally, the distance calculating system further comprises:
the remote information acquisition module is used for acquiring all effective cities with merchants through a preset remote dictionary server if the judging result is that the effective cities are not available; judging whether each effective city contains the target city or not; and if the target city is contained in each effective city, acquiring the merchant information through the remote dictionary server.
Optionally, the distance calculating system further comprises:
the information screening module is used for removing the businesses which stop operating in the target businesses through the operating information in the business information so as to obtain the effective information of each effective business in the target city; and storing each piece of effective information into the memory cache.
Optionally, the distance calculating system further comprises:
the server building module is used for synchronizing data information of all merchants in all cities to a preset elastic search database and a preset remote dictionary server through an external interface, wherein the data information comprises identity information of merchants in all places in each city; taking the names of the cities as city key values of the local merchants of the cities, and splicing and writing the identity information in the elastic search database into the remote dictionary server; and splicing and writing the effective names of the effective cities with the merchants in each city into the remote dictionary server through a preset fixed key value so as to finish the establishment of the remote dictionary server.
The specific implementation manner of the distance calculating system of the present application is basically the same as that of each embodiment of the distance calculating method, and will not be repeated here.
Furthermore, the present application proposes a computer storage medium having stored thereon a distance calculation program which, when executed by a processor, implements the steps of the distance calculation method of the present application as described above.
The specific embodiments of the computer storage medium of the present application are substantially the same as the embodiments of the distance calculating method described above, and are not described herein.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The foregoing embodiment numbers of the present application are merely for the purpose of description, and do not represent the advantages or disadvantages of the embodiments.
From the above description of the embodiments, it will be clear to those skilled in the art that the above-described embodiment method may be implemented by means of software plus a necessary general hardware platform, but of course may also be implemented by means of hardware, but in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in a storage medium (e.g. ROM/RAM, magnetic disk, optical disk) comprising instructions for causing a terminal device (which may be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to perform the method according to the embodiments of the present application.
The foregoing description is only of the preferred embodiments of the present application, and is not intended to limit the scope of the application, but rather is intended to cover any equivalents of the structures or equivalent processes disclosed herein or in the alternative, which may be employed directly or indirectly in other related arts.
Claims (10)
1. A distance calculation method, characterized in that the distance calculation method comprises:
Acquiring point coordinates of a target point and acquiring merchant information of each target merchant in a target city where the target point is located, wherein the merchant information comprises: commercial tenant coordinates;
establishing a distance formula between the point coordinates and target coordinates in each merchant coordinate based on a rectangular diagonal formula;
training the distance formula in a preset fitting range through a polynomial curve fitting algorithm to obtain a trained fitting formula;
and inputting the point coordinates and the merchant coordinates into the fitting formula for calculation to obtain the distance between the target point and each target merchant.
2. The distance calculation method according to claim 1, wherein the point coordinates include: a first longitude and a first latitude, the target coordinates comprising: a second longitude and a second latitude;
the step of establishing a distance formula between the point coordinates and target coordinates in the merchant coordinates based on a rectangular diagonal formula comprises the following steps:
calculating a longitude difference between the first longitude and the second longitude, and calculating an average latitude of the first latitude and the second latitude;
calculating an east-west distance between the point coordinates and the target coordinates according to the longitude difference and the average latitude;
Calculating a north-south distance between the point coordinates and the target coordinates according to the altitude difference between the first latitude and the second latitude;
substituting the east-west distance and the north-south distance into the rectangular diagonal formula to establish a distance formula between the point coordinates and the target coordinates.
3. The distance calculation method according to claim 1, wherein the distance formula includes a trigonometric function term;
the step of training the distance formula in a preset fitting range through a polynomial curve fitting algorithm comprises the following steps:
average cutting out a preset number of sampling points in a preset fitting range;
training each sampling point through a polynomial curve fitting algorithm to obtain a polynomial function fitted with the trigonometric function term;
and replacing trigonometric function terms in the distance formula with the polynomial function to obtain a fitting formula.
4. The distance calculating method according to claim 1, wherein the step of acquiring merchant information of each target merchant in the target city in which the target point is located includes:
determining a target city where the target point is located according to the point coordinates;
Judging whether merchant information of each target merchant in the target city in the memory cache exists or not based on the acquired distance request instruction, and obtaining a judging result;
and if the judging result is that the commercial tenant information exists, acquiring the commercial tenant information from the memory cache.
5. The distance calculating method according to claim 4, wherein after the step of obtaining a judgment result, the method further comprises:
if the judging result is that the business does not exist, acquiring all effective cities of all the owned merchants through a preset remote dictionary server;
judging whether each effective city contains the target city or not;
and if the target city is contained in each effective city, acquiring the merchant information through the remote dictionary server.
6. The distance calculating method according to claim 5, wherein after the step of acquiring each of the merchant information through the remote dictionary service, the method further comprises:
removing the businesses stopping operation in each target business through the operation information in each business information to obtain the effective information of each effective business in the target city;
And storing each piece of effective information into the memory cache.
7. The distance calculating method according to claim 4, wherein before the step of acquiring the merchant information of each target merchant in the target city in which the target point is located, the method further comprises:
synchronizing data information of all merchants in all cities to a preset elastic search database and a preset remote dictionary server through an external interface, wherein the data information comprises identity information of merchants in all places in each city;
taking the names of the cities as city key values of the local merchants of the cities, and splicing and writing the identity information in the elastic search database into the remote dictionary server;
and splicing and writing the effective names of the effective cities with the merchants in each city into the remote dictionary server through a preset fixed key value so as to finish the establishment of the remote dictionary server.
8. A distance computing system, the distance computing system comprising:
the information acquisition module is used for acquiring point coordinates of a target point and acquiring merchant information of each target merchant in a target city where the target point is located, wherein the merchant information comprises: commercial tenant coordinates;
The formula establishing module is used for establishing a distance formula between the point coordinates and target coordinates in the merchant coordinates based on a rectangular diagonal formula;
the formula training module is used for training the distance formula in a preset fitting range through a polynomial curve fitting algorithm so as to obtain a trained fitting formula;
and the distance calculation module is used for inputting the point coordinates and the merchant coordinates into the fitting formula for calculation so as to obtain the distance between the target point and each target merchant.
9. A distance computing device, the distance computing device comprising: a memory, a processor, wherein the memory has stored thereon a distance calculation program which, when executed by the processor, implements the steps of the distance calculation method according to any of claims 1 to 7.
10. A computer storage medium, characterized in that the computer storage medium has stored thereon a distance calculation program which, when executed by a processor, implements the steps of the distance calculation method according to any of claims 1 to 7.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202311128860.9A CN117076846A (en) | 2023-08-31 | 2023-08-31 | Distance calculation method, system, equipment and storage medium |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202311128860.9A CN117076846A (en) | 2023-08-31 | 2023-08-31 | Distance calculation method, system, equipment and storage medium |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN117076846A true CN117076846A (en) | 2023-11-17 |
Family
ID=88704108
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202311128860.9A Pending CN117076846A (en) | 2023-08-31 | 2023-08-31 | Distance calculation method, system, equipment and storage medium |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN117076846A (en) |
-
2023
- 2023-08-31 CN CN202311128860.9A patent/CN117076846A/en active Pending
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US10743178B2 (en) | Reduced resolution location determination for improved anonymity of user location | |
| CN102571910B (en) | Method for searching nearby users in social network, and server | |
| EP2507973B1 (en) | Optimizing caching period of location data for network based location services | |
| US20150370828A1 (en) | Tile-Based Distribution of Searchable Geospatial Data to Client Devices | |
| CN103347297B (en) | Indoor positioning method, indoor positioning server and indoor positioning system | |
| US11151210B2 (en) | Target location search method and apparatus | |
| CN107092623B (en) | Method and device for querying a point of interest | |
| CN105992338B (en) | Positioning method and device | |
| US8996551B2 (en) | Managing geographic region information | |
| US20120295632A1 (en) | Indoor map distribution | |
| US20150057012A1 (en) | Method and system for determining high precision geo-fencing using business property boundaries | |
| WO2020258905A1 (en) | Information pushing method and device | |
| JP6169022B2 (en) | Apparatus, program, and method for estimating staying place of user having portable terminal | |
| CN105512320A (en) | User ranking obtaining method and device and server | |
| CN115243371B (en) | Positioning method, device, electronic device and storage medium | |
| CN110750602B (en) | Method and device for determining site to which order address belongs | |
| CN117076846A (en) | Distance calculation method, system, equipment and storage medium | |
| CN111274272B (en) | Object searching method and device and computer system | |
| CN114205455B (en) | Application positioning processing method and device | |
| CN114173276B (en) | User positioning method and device | |
| CN120216523B (en) | Method, system, device, terminal and medium for logically checking and quality checking vector data | |
| CN105389395B (en) | Information acquisition method and device | |
| CN115515123A (en) | Corresponding relation binding method, device, equipment and readable storage medium | |
| CN106465324B (en) | A data processing method and device | |
| CA2990717C (en) | Method and device for searching for mobile terminal |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination |