GeoNames Home | Postal Codes | Download / Webservice | About 

GeoNames Forum
  [Search] Search   [Recent Topics] Recent Topics   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
SQL to calculate the closest Locations. It is correct?  XML
Forum Index -> General
Author Message
lopes_andre



Joined: 27/07/2010 16:36:40
Messages: 1
Offline

Hi,

I need to calculate the closest locations, but I don't know if the database query is OK. It seems that some Locations are incorrect, but could be invalid dat in the database.

Code:
 select gn1.name as nome_local, gn1.latitude, gn1.longitude, cr.geonames_name as Distrito,
 ACOS(SIN(38.66667)*SIN(gn1.latitude)+COS(38.66667)*COS(gn1.latitude)*COS(gn1.longitude-(-9.06667)))*6371 as D
 from geoname gn1
 join country_regions cr on cr.code = gn1.country || '.' || gn1.admin1
 where
 gn1.country = 'PT'
 --and lower(gn1.name) = 'moita'
 and ACOS(SIN(38.66667)*SIN(gn1.latitude)+COS(38.66667)*COS(gn1.latitude)*COS(gn1.longitude-(-9.06667)))*6371 < 300
 order by D
 


The 300 is mt, kms or other?

Sorry for my bad english.
 
Forum Index -> General
Go to:   
Powered by JForum 2.1.5 © JForum Team