Monday, 8 August 2011

Getting the List of Latitude and Longitude based on GeoCoordinates with in a radius

CREATE function [dbo].[udf_Haversine](@lat1 float, @long1 float,@lat2 float,@long2 float)returns float
begin
declare @dlon float, @dlat float, @rlat1 float,@rlat2 float, @rlong1 float, @rlong2 float,
@a float, @c float, @R float, @d float, @DtoR float
select @DtoR = 0.017453293
select @R=6371 --6371 in km & 3959 in miles ::Earth radius::
select @rlat1 = @lat1 * @DtoR,@rlong1 = @long1 * @DtoR,@rlat2 = @lat2 * @DtoR,@rlong2 = @long2 * @DtoR
select @dlon = @rlong1 - @rlong2,@dlat = @rlat1 - @rlat2
select @a = power(sin(@dlat/2), 2) + cos(@rlat1) * cos(@rlat2) * power(sin(@dlon/2), 2)
select @c = 2 * atn2(sqrt(@a), sqrt(1-@a))
select @d = @R * @c
return @d
end

CREATE PROCEDURE Search_GeoCoordinates(@latitude float,@longitude float,@radius_kms float)
AS
BEGIN
SET NOCOUNT ON;
Begin
select id,houseaddr,latitude,longitude from tbl_house
where dbo.udf_Haversine(CONVERT(Float,ISNULL(latitude,0.00)),CONVERT(Float,ISNULL(longitude,0.00)),@latitude,@longitude)<@radius_kms
End
END

Tag: Latitude,Longitude,Radius,asp.net

No comments:

Post a Comment

Parsing JSON w/ @ symbol in it

To read the json response like bellow @ concatenated with attribute                             '{ "@id": 1001, "@name&q...