को खोजने के लिए कर रहा हूँ कर रहा हूँ
ALTER FUNCTION [dbo].[DistanceBetween] (@Lat1 as real,
@Long1 as real, @Lat2 as real, @Long2 as real)
RETURNS real
AS
BEGIN
DECLARE @dLat1InRad as float(53);
SET @dLat1InRad = @Lat1 * (PI()/180.0);
DECLARE @dLong1InRad as float(53);
SET @dLong1InRad = @Long1 * (PI()/180.0);
DECLARE @dLat2InRad as float(53);
SET @dLat2InRad = @Lat2 * (PI()/180.0);
DECLARE @dLong2InRad as float(53);
SET @dLong2InRad = @Long2 * (PI()/180.0);
DECLARE @dLongitude as float(53);
SET @dLongitude = @dLong2InRad - @dLong1InRad;
DECLARE @dLatitude as float(53);
SET @dLatitude = @dLat2InRad - @dLat1InRad;
/* Intermediate result a. */
DECLARE @a as float(53);
SET @a = SQUARE (SIN (@dLatitude/2.0)) + COS (@dLat1InRad)
* COS (@dLat2InRad)
* SQUARE(SIN (@dLongitude/2.0));
/* Intermediate result c (great circle distance in Radians). */
DECLARE @c as real;
SET @c = 2.0 * ATN2 (SQRT (@a), SQRT (1.0 - @a));
DECLARE @kEarthRadius as real;
/* SET kEarthRadius = 3956.0 miles */
SET @kEarthRadius = 6376.5; /* kms */
DECLARE @dDistance as real;
SET @dDistance = @kEarthRadius * @c;
return (@dDistance);
END
ALTER FUNCTION [dbo].[NearestPeople]
(
@lat real,
@long real,
@maxdist real
)
RETURNS TABLE
AS
RETURN
SELECT Person.ID
FROM Person
WHERE dbo.DistanceBetween(@lat, @long, Latitude, Longitude) < @maxdist
मैं तो इन एसक्यूएल कार्यों सर्वर से इस तरह सी # में का उपयोग करें:: मैं NerdDinner परियोजना से कॉपी किया
public IQueryable<Person> FindNearbyPeople(float latitude, float longitude, float maxdistance)
{
var people = from person in FindAllPeople()
join i in db.NearestPeople(latitude, longitude, maxdistance)
on person.ID equals i.ID
select person;
return people;
}
है कि मुझे जो बताता है (इस मामले में, लोगों) के करीब है मुझे अधिकतम दूरी के भीतर।
यह मुफ़्त संस्करण है। मुझे लगता है कि SQL Server 2008 इसे भौगोलिक पैकेज
स्रोत
2011-01-24 06:02:06