A random motion method based on a baidu map route book and an electronic device
By modifying Baidu Maps' route guide to support multiple paths and embedding animation effects, infinite random movement was achieved, solving the problems of unclear movement trajectories and high memory consumption in existing technologies, and improving the response speed of animation effects.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-25
- Publication Date
- 2026-03-20
AI Technical Summary
Existing technologies suffer from unclear motion trajectories during path planning, making it impossible to achieve random motion. They also consume a lot of memory, have a high error rate, and produce slow animation effects, making it impossible to achieve infinite motion.
The Baidu Maps route guide was modified to support multiple route segments, each with embedded animation effects. By randomly selecting routes, the animation effects were made to loop infinitely.
It enables infinite random movement of a single road map instance, reducing memory consumption and error rate, and improving the response speed of animation effects.
Smart Images

Figure CN117194594B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of map navigation, and particularly relates to a random motion method based on a Baidu map route book and an electronic device. BACKGROUND
[0002] Maps are increasingly widely used in various field systems, which also makes some operations on the map more and more commonly used by people, such as drawing a marker point on the map, circumscribing an area on the map, setting a position on the map, and planning a path on the map. When the path is currently planned, a static map from a starting point to an ending point is obtained. This method has the problem that the specific progress is not clear, that is, the order of each coordinate point is not clear, and the motion trajectory is not clear and intuitive. When the animation effect of the motion trajectory is performed, the current motion effect of the path can only be displayed, a single instance cannot realize the random motion effect, and infinite motion must be repeatedly created. The route book instance has large memory consumption, high error rate, slow response, and lacks in infinite motion, and cannot realize a good animation effect. SUMMARY
[0003] The present application relates to the technical field of map navigation, and particularly relates to a random motion method based on a Baidu map route book and an electronic device.
[0004] To achieve the above object, the present application provides the following technical scheme: a random motion method based on a Baidu map route book, the method comprising:
[0005] The Baidu map route book is modified, and backend data is obtained to make it a multi-segment path that can be loaded on the Baidu map, and each path is implanted with an animation effect;
[0006] A path is randomly selected, and the animation effect of the path is loaded into the Baidu map to realize that the marker of the Baidu map displays the animation effect according to the path.
[0007] Further, the obtaining of the backend data to make it a multi-segment path that can be loaded on the Baidu map comprises:
[0008] An asynchronous request is sent to the backend database through Axios to obtain a data containing a coordinate point array, each element in the array is an array of two latitude and longitude objects, and the array is a three-dimensional array;
[0009] The three-dimensional array is converted into a coordinate point object available for the Baidu map, and is spliced into a two-dimensional array;
[0010] A random number is used to generate an index for obtaining a random one-dimensional array data in the two-dimensional array;
[0011] Traverse the generated two-dimensional array, call the API of Baidu map to generate several line segments, which are used to mark the route book motion trajectory.
[0012] Further, the de-duplication and splicing of the three-dimensional array into a two-dimensional array includes: using the array method forEach nested method combined with the API of Baidu map to convert the objects in the two-dimensional array into latitude and longitude objects in Baidu map, and using the array concat method to splice after de-duplication to obtain an array, the elements in the array are an array of several latitude and longitude objects, and the three-dimensional array is reduced to a two-dimensional array, and the objects are converted into point objects available for Baidu map API;
[0013] Further, the use of random number generation index includes: using the random number generation method Math.random to generate an index corresponding to the line segment, which is used to obtain a random one-dimensional array data in the two-dimensional array to switch the path of the route book animation motion.
[0014] Further, the reconstruction of the Baidu map route book includes: introducing the route book plug-in, creating the route book, implanting animation effect in each path, adding judgment and assignment of variable cb in the start method of the route book, adding judgment and execution of variable cb in the moveNext method of the route book, and adding nulling of variable cb in the stop method of the route book.
[0015] Further, the addition of judgment and assignment of variable cb in the start method of the route book, the addition of judgment and execution of variable cb in the moveNext method of the route book, and the addition of nulling of variable cb in the stop method of the route book include:
[0016] A function variable cb is passed into the start method of the route book, and the passed-in function variable cb is initialized, the function variable cb is used to change the function executed next;
[0017] In the moveNext method of the route book, it is judged whether the step length of the movement is sufficient, whether the animation moves to the end of the line segment, and if the animation moves to the end of the passed-in line segment, the passed-in function variable cb is executed;
[0018] In the stop method of the route book, the timer and the passed-in function variable cb are destroyed.
[0019] Further, a path is randomly selected, and the animation effect of the path is loaded into the Baidu map to realize the marker of the Baidu map displaying the animation effect according to the path, including: a recursive function for recursively calling the start method of the road book is written, and the recursive function randomly selects the path to be animated by the road book when executed.
[0020] Further, the recursive function for recursively calling the start method of the road book is written, and the recursive function randomly selects the path to be animated by the road book when executed.
[0021] The recursive function change method for recursively calling the start method of the road book is written, and the recursive function change method uses the path selected by the random number index as the track of the animation movement of the road book at each time of calling, calls the start method of the road book, and transmits the recursive function change method to the start method of the road book for recursive calling;
[0022] The recursive function change method is initialized, the movement of the animation is started, and the animation effect of the road book with infinite random movement is realized.
[0023] An electronic device includes a memory and a processor, the memory stores program instructions, and the processor executes the program instructions to perform the steps in the random motion method based on the Baidu map road book.
[0024] Compared with the prior art, the beneficial effects of the present application are: the Baidu map road book is modified to become a multi-segment path that can be loaded on the Baidu map, and each path is implanted with an animation effect, a path can be randomly selected, and the animation effect of the path is loaded into the Baidu map to realize the marker of the Baidu map displaying the animation effect according to the path, a new path is selected as the target of the next animation movement according to the generated random number after each animation movement ends, and the cycle is executed continuously, so that the animation is always in a state of random switching movement, a method for completing random movement along different tracks and infinite movement using a single road book instance is realized, and problems such as large memory consumption, high bit error rate, and slow reaction caused by creating multiple road book instances are solved. BRIEF DESCRIPTION OF DRAWINGS
[0025] Figure 1 The random motion method based on the Baidu map road book of the present application is a flowchart;
[0026] Figure 2 The method flowchart for obtaining the backend data to become a multi-segment path that can be loaded on the Baidu map of the present application is a flowchart; DETAILED DESCRIPTION
[0027] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work fall within the protection scope of the present application.
[0028] As shown in the figure, the embodiment provides a random motion method based on a Baidu map route book, and the method comprises the following steps: Figure 1
[0029] S1: The Baidu map route book is modified, and backend data is acquired to make it a multi-segment path that can be loaded on the Baidu map, and each path is implanted with an animation effect;
[0030] S2: A path is randomly selected, and the animation effect of the path is loaded into the Baidu map to realize that the marker of the Baidu map displays the animation effect according to the path.
[0031] To realize the animation effect, the Baidu map API provides a BMapGLLib.LuShu component, that is, a route book plug-in. By introducing the route book plug-in, a route book object can be created, and the method of the object is called to control the motion of the animation. Specifically, the BMapGLLib.LuShu constructor function in the route book plug-in can be used to create a route book object, and the start() method of the object can be used to start the motion of the animation. The following example code demonstrates how to use the route book plug-in:
[0032] / / Create a map instance
[0033] const map = new BMap.Map("map-container");
[0034] / / Create a route book object
[0035] const route = new BMapGLLib.LuShu(map, pointsArray, { / * configuration item * / });
[0036] / / Start the animation motion
[0037] route.start();
[0038] The pointsArray in the above code is an array containing a series of latitude and longitude coordinate points, used to specify the path of the animation, so that each path is implanted with animation effects. The reconstruction of the Baidu Map route book in this embodiment includes: adding judgment and assignment of the variable cb in the start method of the route book, adding judgment and execution of the variable cb in the moveNext method of the route book, and adding nulling of the variable cb in the stop method of the route book; specifically, the source code of the Baidu Map route book can be found on the official document or code hosting platform such as GitHub, the source code is downloaded to the local, the source code of the route book entity class is parsed, all methods mounted on the prototype chain are analyzed in depth, the start method is found in the source code of the route book, and the parameter list of the start method is modified, a new parameter is added to receive the function variable, a function variable is passed into the start method of the route book, and the passed-in function variable cb is initialized, for example, the definition of the start method can be modified as: start(cb){...}, wherein cb is the parameter for receiving the function variable, the passed-in function variable can be initialized in the start method, for example, the function is assigned, the parameter is passed, and the like, to initialize the state of the function, the initialized function variable is used to perform corresponding operations, following the execution order and logic of the function, the method named_moveNext is found in the source code, which is used to move the animation to the next point or line segment, code is added in the_moveNext method, which is used to judge whether the step length of the current movement is sufficient, whether the step length meets the condition can be judged by comparing the current animation position and the position of the next point or line segment, for example, whether the distance from the current position to the target position is less than or equal to the preset step length can be checked, if the step length is sufficient, that is, the animation has moved to the end of the passed-in line segment, the passed-in function variable is executed, and the passed-in function variable is operated when the condition is met; the method named stop is found in the source code, which is used to pause or stop the animation movement, in the stop method, a timer function such as setTimeout or setInterval is used to realize the delay effect of pausing or stopping, for example, a timer is created in the stop method, and a specific operation is performed after a certain delay time, the passed-in function variable cb is destroyed through appropriate code, for example, the function variable is set to null or undefined, to release the memory space occupied by the function variable;
[0039] Then the backend data is acquired to become a multi-segment path that can be loaded on the Baidu Map, as shown in Figure 2 The following steps are included:
[0040] S11: Obtain a data containing coordinate point array from the background database by sending an asynchronous request through Axios, each element in the array is an array of two latitude and longitude objects, the array is a three-dimensional array;
[0041] S12: Convert the three-dimensional array to a coordinate point object available for Baidu Map, and splice it into a two-dimensional array;
[0042] S13: Use random number to generate index, which is used to obtain a random one-dimensional array data in the two-dimensional array;
[0043] S14: Traverse the generated two-dimensional array, call the API of Baidu Map to generate several line segments, which are used to mark the route book movement trajectory.
[0044] Specifically, an asynchronous request is sent to the API endpoint of the background database using Axios to obtain a data containing coordinate point array, Axios is a Promise-based HTTP client, the response processing function of Axios processes and converts the response data, and in the conversion process, a three-dimensional array containing N arrays of two latitude and longitude objects is constructed using conventional JavaScript operations and methods, the following example code demonstrates the obtained three-dimensional array:
[0045]
[0046]
[0047] After obtaining the three-dimensional array, the object in the two-dimensional array is converted to the latitude and longitude object in Baidu Map using the array method forEach nested with the API of Baidu Map, and after deduplication, the array is spliced using the concat method of the array, the element in the array is an array of several latitude and longitude objects, which reduces the three-dimensional array to a two-dimensional array, and converts the object in the array to a point object available for Baidu Map API, the following is the example code:
[0048]
[0049]
[0050] A random number generation method Math.random is used to generate an index corresponding to a line segment, which is used to obtain a random one-dimensional array data in a two-dimensional array to switch the path of the road book animation movement. For example, a random number between 0 and 1 is generated using the Math.random() method, the random number is multiplied by the number of line segments, and the result is rounded down to obtain an index corresponding to the number of line segments. A random one-dimensional array data in a two-dimensional array is obtained using the generated random index through index operation. The following is an example code:
[0051] let index = Math.round(Math.random() * (that.lineArrList.length - 1));
[0052] The generated two-dimensional array is traversed, and the API of Baidu Map is called to generate a plurality of line segments for marking the road book movement trajectory. The following is an example code:
[0053]
[0054] A recursive function change method is written for the start method of the road book, and the recursive function change method uses the path selected by the random number index as the trajectory of the road book animation movement in each call. The start method of the road book is called, and the recursive function change method is passed as a parameter for recursive call in the start method of the road book. The following is an example code:
[0055]
[0056] The recursive function change method is initialized, and the animation movement is started. The following is an example code:
[0057]
[0058] In this way, the animation effect of the randomly selected path is loaded into the Baidu Map, the marker of the Baidu Map is displayed according to the path, and the road book animation effect of infinite random movement is realized.
[0059] The embodiment also provides an electronic device, which includes a memory and a processor. The memory stores program instructions. When the processor runs the program instructions, the steps in the random movement method based on the road book of Baidu Map are executed. The electronic device can be a computer, a tablet computer or the like.
[0060] The present application transforms the Baidu map route book into a multi-section path which can be loaded on the Baidu map, and each path is implanted with an animation effect, a path can be randomly selected, and the animation effect of the path is loaded into the Baidu map, so that the marker of the Baidu map displays the animation effect according to the path, after each animation movement ends, a new path is selected as the target of the next animation movement according to the generated random number, and the process is repeatedly executed, so that the animation is always in a state of random switching movement, and the method for completing random movement along different trajectories and infinite movement by using a single route book instance is realized, and the problems of large memory consumption, high error rate and slow reaction caused by creating multiple route book instances are solved.
[0061] Although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art can modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacements to part of the technical features, and any modification, equivalent replacement, improvement, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.
Claims
1. A random motion method based on Baidu Maps route guides, characterized in that, The method includes: The Baidu Maps route book was modified by introducing a route book plugin to create route books, embedding animation effects into each path. In the `start` method of the route book's start motion, a function variable `cb` is passed in and initialized. This function variable `cb` is used to modify the function executed next. In the `moveNext` method of the route book's movement motion, it checks if the step size is sufficient by comparing the current animation position with the position of the next point or line segment. It also checks if the distance from the current position to the target position is less than or equal to the preset step size. If the step size is sufficient, i.e., the animation moves to the end of the line segment, and the conditions are met, the passed-in function variable `cb` is executed and operated on. In the `stop` method of the route book's end motion, a timer is used, and the passed-in function variable `cb` is destroyed. The backend data is obtained and transformed into multiple paths that can be loaded on Baidu Maps, with each path having an animation effect. A path is randomly selected, and the animation effect of the path is loaded into Baidu Maps so that the Baidu Maps markers are displayed with animation effects according to the path.
2. The random motion method based on Baidu Maps route book according to claim 1, characterized in that: The process of obtaining backend data to create multiple paths that can be loaded on Baidu Maps includes: A asynchronous request is sent via Axios to retrieve data containing an array of coordinate points from the backend database. Each element in the array is an array of two latitude and longitude objects, and the array is a three-dimensional array. Convert the 3D array into duplicate coordinate point objects usable by Baidu Maps and concatenate them into a 2D array. Use random numbers to generate indices to retrieve random one-dimensional array data from a two-dimensional array; Iterate through the generated two-dimensional array and call the Baidu Maps API to generate several line segments to mark the movement trajectory of the route book.
3. The random motion method based on Baidu Maps route book according to claim 2, characterized in that, The process of converting a three-dimensional array into a coordinate point object usable by Baidu Maps, removing duplicates, and concatenating them into a two-dimensional array includes: using the nested array method `forEach` in conjunction with the Baidu Maps API to convert the objects in the two-dimensional array into latitude and longitude objects in Baidu Maps; after removing duplicates, using the array's `concat` method to concatenate them to obtain an array. The elements in the array are an array of several latitude and longitude coordinates as objects, thereby reducing the three-dimensional array to a two-dimensional array and converting the objects in it into point objects usable by the Baidu Maps API.
4. The random motion method based on Baidu Maps route book according to claim 2, characterized in that, The method of generating subscripts using random numbers includes: using the random number generation method Math.random to generate a subscript corresponding to a line segment by rounding down, which is used to obtain a random one-dimensional array data in the two-dimensional array to switch the path of the route book animation.
5. The random motion method based on Baidu Maps route book according to claim 1, characterized in that: Randomly select a path and load the animation effect of the path into Baidu Maps so that the Baidu Maps marker displays the animation effect according to the path. This includes writing a recursive function to recursively call the start method of the road book. When the recursive function is executed, it randomly selects the path of the road book to be animated.
6. The random motion method based on Baidu Maps route book according to claim 5, characterized in that: The recursive function used to recursively start the movement of the route book includes, when the recursive function is executed, randomly selecting the path to be moved in the route book, including: Write a recursive function `change` to recursively call the `start` method of the road book animation. Each time the `change` function is called, it selects a path with a random index as the trajectory of the road book animation, calls the `start` method of the road book, and passes the recursive function `change` into the `start` method of the road book for recursive calling. The recursive function `change` is initialized to start the animation, achieving an infinitely random road map animation effect.
7. An electronic device, characterized in that, The electronic device includes a memory and a processor. The memory stores program instructions. When the processor runs the program instructions, it executes the steps of the random motion method based on Baidu Maps route book according to any one of claims 1 to 6.
Citation Information
Patent Citations
Trajectory generation method and related device
CN111563618A