0

I'm working with google maps API and have a few coordinates (markers) around the world. How is the best way to get a marker list of the points inside a mile with an 'A' marker on center ?

The first way I think is calculate the distance between the point A and all others points and sort the array. It works, but takes n interactions.

The second way would store the coordinates and a 'chunk' (city, state, country), and repeat the previous method, searching only inside this "chunk". It's still n, but now the 'n' is smaller.

What is the best way to store the data and work on it ?

Md Golam Rahman Tushar
  • 2,175
  • 1
  • 14
  • 29
  • Your question is **too broad** and it's unclear. How are you storing the coordinates? What have you tried so far? Did you make any research before asking? https://stackoverflow.com/questions/16561296/finding-nearest-locations-using-google-maps-api/16563642 – MrUpsidown Feb 08 '19 at 09:57

1 Answers1

0

You could store several ordered index- and coordinate-lists, each based on either x, y, or z, or longtitude or latitude information.

For example:

Points = {(2,3), (6,4), (7,1), (1, 9)};

xList = {1, 2, 6, 7};
xIndexList = {3, 0, 1, 2};

yList = {1, 3, 4, 9};
yIndexList = {2, 0, 1, 3};

Then you can filter the x-values within 1 mile from the x-coordinate of A and the same for the y-values and consider only the overlap of these indices. (You should still do a distance check for these points afterwards.)

It is a bit cumbersome though, and one should be careful around the poles and date-lines if using spherical coordinates, but it is at least fast.

MinosIllyrien
  • 330
  • 1
  • 9