-1

how do I write a query based on distance, its a bit hard to explain but heres what I am looking for

On websites like gum tree, there is an option which says "WITH IN MILES" +10 miles, +5 miles e.t.c.

  • How do I calculate the area based on the city or postcode provided by the user.

  • How will the query execute and return results based on this search. thank you.

    Im using PHP and MYSQL for this project.

Community
  • 1
  • 1
  • What have you tried so far? Are these cached distances that you'll be querying? Or using an API like Google Maps to calculate them realtime? – kchason Oct 30 '17 at 14:13
  • This question has been [answered](https://stackoverflow.com/questions/8994718/mysql-longitude-and-latitude-query-for-other-rows-within-x-mile-radius) [already](https://gis.stackexchange.com/questions/31628/find-points-within-a-distance-using-mysql) [mutliple](https://stackoverflow.com/questions/24370975/find-distance-between-two-points-using-latitude-and-longitude-in-mysql) [times](https://stackoverflow.com/questions/1006654/fastest-way-to-find-distance-between-two-lat-long-points) – apokryfos Oct 30 '17 at 14:18
  • I have not tried any thing yet. I know one way of doing so Is by using the post office data base. which costs around 5200 pounds, which is not an option. I have seen some one using javascript on google maps api to extract the information but I am not sure how that works with the query. for example a product located in an area 10 miles away from the area requested in. – Malik Ali Oct 30 '17 at 14:20

1 Answers1

1

Distances like that are calculated using the haversine formula using the latitude and longitude of two points. The lat and long data is widely available through simple Google searches.

Spencer
  • 297
  • 2
  • 10