Determine el código iso del país a partir de coordenadas GEO

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

first you are asking for country iso code, then for the nearest city. what exactly are you looking for? -

In your title, you talk about the country's ISO code, in the question body, you talk about the nearest city. Which one is it? Also, what defines a "city" in this context? -

I guess he skipped a step, as the cities table probably contains a reference to countries with their ISO codes. -

Well for each city I have the country iso code, that I mean. But a sifrst I need to get the nears city. -

2 Respuestas

Maybe I misunderstood the question, but if you have:

  1. [X1,Y1] - the coordinates of your position
  2. [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.

Respondido el 09 de enero de 11 a las 14:01

http://www.davidus.sk/web/main/index/article_id/8

There you go, distance is actually a radius. It will return all cities within it.

Respondido el 09 de enero de 11 a las 14:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.