I have created an SSRS reports in which i'm using map along with bing map. Also i have using the Point layer in the map. How can i able to get distance between 2 points in the map? Kindly advice...
Asked
Active
Viewed 966 times
0

Tae-Sung Shin
- 20,215
- 33
- 138
- 240

user1441204
- 1
- 1
- 4
-
May be this will help http://stackoverflow.com/questions/8907873/distance-between-two-points-using-geography-datatype-in-sqlserver-2008 – praveen Dec 17 '12 at 08:36
2 Answers
1
The below function gives you distance between two GeoCoordinates in kilo metres
CREATE FUNCTION dbo.fnCalcDistanceKM(@lat1 FLOAT, @lat2 FLOAT, @lon1 FLOAT, @lon2 FLOAT)
RETURNS FLOAT
AS
BEGIN
RETURN ACOS(SIN(PI()*@lat1/180.0)*SIN(PI()*@lat2/180.0)+COS(PI()*@lat1/180.0)*COS(PI()*@lat2/180.0)*COS(PI()*@lon2/180.0-PI()*@lon1/180.0))*6371
END
The below function gives you distance between two GeoCoordinates in miles
create function [dbo].[fnCalcDistanceMiles] (@Lat1 decimal(8,4), @Long1 decimal(8,4), @Lat2 decimal(8,4), @Long2 decimal(8,4))
returns decimal (8,4) as
begin
declare @d decimal(28,10)
-- Convert to radians
set @Lat1 = @Lat1 / 57.2958
set @Long1 = @Long1 / 57.2958
set @Lat2 = @Lat2 / 57.2958
set @Long2 = @Long2 / 57.2958
-- Calc distance
set @d = (Sin(@Lat1) * Sin(@Lat2)) + (Cos(@Lat1) * Cos(@Lat2) * Cos(@Long2 - @Long1))
-- Convert to miles
if @d <> 0
begin
set @d = 3958.75 * Atan(Sqrt(1 - power(@d, 2)) / @d);
end
return @d
end
Usage:
select [dbo].[fnCalcDistanceKM](13.077085,80.262675,13.065701,80.258916)

Community
- 1
- 1

Durai Amuthan.H
- 31,670
- 10
- 160
- 241
0
If you know the OS co-ordinates (latitude and longitude) of both points you can calculate it using a bit of Pythagoras:
SQRT(((lat1 - lat2) * (lat1 - lat2)) + ((long1 - long2) * (long1 - long2)))
This calculates the differences between the two points on the X and Y axis which become the two short sides of an equatorial triangle with the longest side, the hypotenuse, being the distance you want to calculate. So it becomes the squares of the two known sides added together gives the square of the hypotenuse, the square root of which gives you you distance.

Dave Sexton
- 10,768
- 3
- 42
- 56