The tutorial shared today is to teach you how to implement nearby people or other content. The server uses PHP. Before using it, please confirm whether your user data table stores the user's latest coordinates and update time. *** Create a separate table to store the user's latest coordinates and update time. Before getting nearby people, you must first get your own coordinates. You can use baiduLocation to get the coordinates of the current user, and then use the current coordinates to request the server to return user data sorted by distance.
//After successfully obtaining the location, the developer sends a request to the server
In fact, the code on the APP side is very simple. It mainly obtains the coordinates and sends them to the server. The server then calculates the distance based on the transmitted coordinates and returns the data in order of distance. So the key point is how the server side implements Let's take PHP as an example on the server side. First, get the data of the user with coordinates. This is foreach. Then calculate the distance based on the passed coordinates. The following is a piece of code in foreach
Then foreach the new array and sort it by distance
Note: There is a custom function distanceBetween() in the foreach above; This is used to calculate the distance between two coordinates. The code is as follows:
|
<<: A good article to solve your doubts: HD multi-screen adaptation solution for mobile H5 pages
>>: 10 Best JavaScript Development Practices You Need to Know
"The sun is just the primary puzzle of the u...
The problem encountered in the recent project is ...
Push is the most cost-effective and direct market...
Everyone knows that in order to survive, organism...
I have been independently operating my company...
Training course video lecture content introductio...
A friend asked me yesterday: How long do you thin...
Whether it was Ant Group and JD Digits preparing ...
Unlike the TV industry, which has been in deep tr...
Why can't I search for the notes I posted? Wh...
In my childhood memory, there was always a radio ...
On February 27, Spreadtrum Communications announc...
Unlike consumer Internet, industrial Internet int...
The invention of the microscope first expanded pe...