Formulas to Calculate Geo Proximity

The Law of Cosines and the Haversine Formula will give identical results assuming a machine with infinite precision. The Haversine formula is more robust to floating point errors. However, today’s machines have double precision of the order of 15 significant figures, and the law of cosines may work just fine for you. Both these formulas … Read more

Java double vs BigDecimal for latitude/longitude

Using double has enough precision for accurate lat/lon down to inches for 6-7 decimal places. In aviation, if decimal degrees are used, they typically go to at least 7 decimal places. In our NASA simulations, lat/lon data are doubles while all other attitude and altitude are floats. In other words, the 6th decimal place for … Read more

Given the lat/long coordinates, how can we find out the city/country?

Another option: Download the cities database from http://download.geonames.org/export/dump/ Add each city as a lat/long -> City mapping to a spatial index such as an R-Tree (some DBs also have the functionality) Use nearest-neighbour search to find the closest city for any given point Advantages: Does not depend on an external server to be available Very … Read more