Monday, 22 August 2016

Finding nearby longitude and latitude within specific distance in database

 To get near by cities which are having longitude and latitude within specific distance in database

SELECT * FROM
(
SELECT * FROM
(
SELECT *,(((acos(sin((@latitude*pi()/180)) * sin((Latitude*pi()/180))+cos((@latitude*pi()/180))
 * cos((Latitude*pi()/180)) * cos(((@longitude - Longitude)*pi()/180))))*180/pi())*60*1.1515*1.609344) as distance
 FROM tblCities
) t
)x where distance <= 1000
ORDER by distance