1

I would like to implement a search by distance on a website. There must be a user in a living city can find all users living within 100 or 200 km for example.

I have a table in my database that stores all the cities and their coordinates.

I thought to create another table that would store the distance between all cities but my data base contains 36,000 cities and it may make a lot of records ...

How could I make this search more simply knowing that my project will be developed with Symfony and Doctrine?

Thank you beforehand

Ahmed Salman Tahir
  • 1,783
  • 1
  • 17
  • 26
Avrel
  • 103
  • 1
  • 4

2 Answers2

2

You can use the correct answer here to determine the distance between co-ordinates.

Measuring the distance between two coordinates in PHP

Community
  • 1
  • 1
lal_bosdi
  • 163
  • 3
  • 13
1

For performance reasons you need to use geospatial index to efficiently query such a database. For example MongoDB has a feature for this.

If performance is not an issue you can simply store locations in relational database table and calculate distances in SQL. See this question for some information about this solution: Geo-Search (Distance) in PHP/MySQL (Performance)

Community
  • 1
  • 1
vbo
  • 13,583
  • 1
  • 25
  • 33