sql - Geographic coordinates in PostgreSQL query -


there 2 fields in database table, latitude , longitude. (other fields too, not important now.)

i have function, 3 parameters: latitude, longitude , max_distance (km).

is there way construct raw postgresql query returns rows represent location within max_distance (km) measured given latitude , longitude?

example parameters latitude=59.9138699, longitude=10.7522451, max_distance=10

to this, use postgis.

postgis has functions such st_distance , st_pointfromtext:

select * tbl st_distance(     st_pointfromtext('point(' || longitude || ' ' || latitude || ')', 4326),      st_pointfromtext('point(10.7522451 59.9138699)', 4326) ) < 10000; 

to fast, should use geometry field , index it.


you should learn bit spatial reference systems , srid. srid 4326 denotes wgs84 coordinate system, commonly in use on web.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -