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
In the initial stage of a startup team, how shoul...
How to extract value and potential opportunities ...
Your browser does not support the video tag Autho...
The storage capacity of smartphones is getting big...
Today I’m going to share with you some basic thro...
In August this year, Intel launched the sixth-gen...
Have you ever had this experience: when you see b...
Everyone's speculation about this year's ...
PSM is not suitable for all marketing scenarios. ...
Album Introduction If you are—— ◎The newly marrie...
How strong is BYD? It has representative models i...
Recently, Austrian researchers announced that the...
With the arrival of Omicron and the increase in b...
On August 2, Apple released the iOS 16.6 update l...
I wish you all a happy Year of the Tiger! Mixed k...