tags:

views:

49

answers:

4

I have a list of cities, each of them obviously has a longitude and latitude.

Now selecting one of these cities, i want to obtain all the other cities that have a longitude / latitude in a range of 50 km from the selected city. What formula should I use?

I am only interested in the mathematical formula to convert km to latidutine and longitude from a know city position

Then i will calculate the maximum and minimum latitude and longitude, for considering an acceptable range. (like a Square)

tks

+2  A: 

You'd probably want to use the Haversine formula.

You may want to check out the following articles for further reading and for a few implementations in various languages:

Daniel Vassallo
A: 

You are looking for the Great Circle calculation. It returns the shortest distance across the surface of the planet given two points and their respective latitude and longitude. There is a great Wikipedia article here: http://en.wikipedia.org/wiki/Great-circle_distance

There is a pretty decent implementation - source code in javascript here: http://trac.osgeo.org/openlayers/wiki/GreatCircleAlgorithms

mistrmark
A: 

If you have the lat long information in UTM you can use the following simple formula:

(Lat2-Lat1)^2 + (Lon2-Lon1)^2 <= (50,000)^2

If you are using a different system I recommend you take a look at the following web site: http://www.uwgb.edu/dutchs/usefuldata/utmformulas.htm

It explains how to convert between the different coordinate systems. It also provides a spread sheet that can be used to translate.

Be happy, and enjoy life

Julian