Я использую TINYINT (1) для хранения булевых значений в Mysql.
я не знаю, существует ли какое-либо преимущество для использования этого... Но если я не ошибаюсь, mysql может сохранить булевскую переменную (BOOL), и это хранит его как tinyint (1)
http://dev.mysql.com/doc/refman/5.0/en/other-vendor-data-types.html
Use an approximation of the earth and the Haversine formula. You can get a javascript version on the following url, which you can translate to your language of choice:
http://www.movable-type.co.uk/scripts/latlong.html
Here is another way: http://escience.anu.edu.au/project/04S2/SE/3DVOT/3DVOT/pHatTrack_Application/Source_code/pHatTrack/Converter.java
Вы ищете длину Великого Кругового Пути между двумя точками на сфере. Попробуйте поискать в Google "Великий круговой путь" или "Великий круговой путь".
Извините, я даже не знаю, в какой вы стране. Мы говорим о востоке и севере (Великобритания, система Ordance Survey), широте и долготе или какой-либо другой системе?
Если мы говорим о востоке и севере, вы можете использовать
sqr ((x1-x2) ^ 2 + (y1-y2) ^ 2)
Это не учитывает того факта, что Земля представляет собой шар, но на небольших расстояниях вы этого не заметите. Мы используем его на работе для определения расстояний между пунктами в округе.
Будьте осторожны с тем, как долго вы используете ссылку на сетку. Я думаю, что 8-значная ссылка даст вам расстояние в метрах. Я смогу получить точный ответ на работе на следующей неделе, если его никто не предоставит.
The pythagorean theorem as offered up by others here doesn't work so well.
The best, simple answer is to approximate the earth as a sphere (its actually a slightly flattened sphere, but this is very close). In Haskell, for instance you might use the following, but the math can be transcribed into pretty much anything:
distRadians (lat1,lon1) (lat2,lon2) =
radius_of_earth *
acos (cos lat1 * cos lon1 * cos lat2 * cos lon2 +
cos lat1 * sin lon1 * cos lat2 * sin lon2 +
sin lat1 * sin lat2) where
radius_of_earth = 6378 -- kilometers
distDegrees a b = distRadians (coord2rad a) (coord2rad b) where
deg2rad d = d * pi / 180
coord2rad (lat,lon) = (deg2rad lat, deg2rad lon)
distRadians
requires your angles to be given in radians.
distDegrees
is a helper function that can take lattitudes and longitudes in degrees.
See this series of posts for more information on the derivation of this formula.
If you really need the extra precision granted by assuming the earth is ellipsoidal, see this FAQ: http://www.movable-type.co.uk/scripts/gis-faq-5.1.html
Здесь можно найти версию SQL Server 2000 Поиск расстояния по широте / долготе SQL Server Zipcode