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
Without further ado, the full article is structur...
Although mini programs have been around for quite...
China's "Sky Eye", Shenzhou spacecr...
I just saw an article analyzing Changyu, pointing...
The Rio Olympics may be the most worrying Olympic...
The National Space Administration announced on Ap...
Preface The hotel business department is one of C...
When you walk on the street, do you always feel l...
Performance optimization is a very broad topic. T...
In the Internet era, product competition is fierc...
The Metaverse is on the rise, and its hot scene s...
I worry about writing creative ideas every day Ho...
With the advent of the 5G era, the Internet has b...
[[197795]] This is an article about Android code ...
In the past two days, many friends have reported ...