php - Reorder list of locations, based on distance to current GPS position -
I have a website that has a list of locations. I want to keep the default selection as the location closest to the user's current location.
I know how to use the current GPS location Javascript, but the problem is that getting the location takes some time, and I want to display the form immediately, and just re-order / Select the closest item when (or if) the location is retrieved.
I have never used the jacquery - can anyone give me some initial help? / P>
The locations are stored in a MySQL DB and I use PHP to retrieve data.
If you want to receive it, then you should follow these steps:
- Select all the locations in the database with their coders.
- In user location cord store session
- Select all the locations from the database in an array and rearrange it by using the function below (Sessions from User Cores and Databases
- Select the new display from Arra y result
original post
var rad = function (x) ) {Return x * Math.PI / 180; }; Var getDistance = function (P1, P2) {var R = 6378137; // Earth means radius meter var dLat = rad (p2.lat () - p1.lat ()); Var dLong = rad (p2.lng () - p1.lng ()); Var a = Math.sin (dLat / 2) * Math.sin (dLat / 2) + Math.cos (rad (p1.lat ()) * Math.cos (rad (p2.lat ()) * Math. Sign (DLF / 2) * Math sin (dLong / 2); Var c = 2 * Math.atan2 (Math.sqrt (a), Math.sqrt (1 - A)) Var D = R * C; Return Returns the distance in D; //};
Comments
Post a Comment