# B4J QuestionGPS position archive procedure and search for the 'nearest' points

#### amorosik

##### Expert
I'm trying to understand how to proceed to create an archive of information relating to scooters located in the city
In addition to the factory and model and serial number there will also be fields for the current geographical position, essentially two fields X=latitude and Y=longitude
I would then like to perform the search to show on the video the 10 scooters closest to the
How to select the 10 scooters 'closest' to a certain position among the 1000 available?

#### Daestrum

##### Expert
Longtime User
copilot said this - where mx,my is your location and x,y is the scooters location
B4X:
``````SELECT
location_id,
x,
y,
-- Calculate distance using Haversine formula
6371 * ACOS(
) AS distance
FROM
your_table
ORDER BY
distance
LIMIT 10;``````

#### tchart

##### Well-Known Member
Longtime User
copilot said this - where mx,my is your location and x,y is the scooters location
B4X:
``````SELECT
location_id,
x,
y,
-- Calculate distance using Haversine formula
6371 * ACOS(
) AS distance
FROM
your_table
ORDER BY
distance
LIMIT 10;``````
Nice but copilot is over complicating it.

For comparing small distances just use Pythagoras to calculate a distance between two x/y pairs. It may not be as accurate but it’s good enough for sorting points to find the closest 10 etc.

I know this from when I used to write software that warned of speeding cameras. The software had a radar display of the closest cameras.

Longtime User
see

Replies
1
Views
2K
Replies
0
Views
1K
Replies
11
Views
8K
Replies
1
Views
3K
Replies
18
Views
3K