I have a MySQL table with cities, and for each city I have the geo coordinates. I want to build a query that determines the nearest city given coordinates of any random position. Can anyone give me an example?
preguntado el 09 de enero de 11 a las 11:01
Maybe I misunderstood the question, but if you have:
- [X1,Y1] - the coordinates of your position
- [Xn,Yn] - for each city
Then why not just calculate the distance using the simple
sqrt((X1-Xn)^2 + (Y1-Yn)^2) ¿fórmula?
You could optimize it further be making some clever selects, to only get the vicinity of the position from the DB and then run the distance measuring on these cities.