Calculate Distance Between Two Points

  • Comments posted to this topic are about the item Calculate Distance Between Two Points

  • You could also use the STDistance function on 2 geo columns/objects?

  • I noticed you were using and passing floats rather than the new spacial data types introduce in SQL Server 2008. Any reason why?

  • Very nice script but it's not stable.

    Check the following examples:

    1. select dbo.MyDistance(46.192131,21.274666,46.192131,21.274665)

    2. select dbo.MyDistance(46.192131,21.274666,46.192131,21.274666)

    Both examples will give the following error:

    Msg 3623, Level 16, State 1, Line 1

    An invalid floating point operation occurred.

    Keep improving it!

  • MSzI (6/15/2012)


    Very nice script but it's not stable.

    Check the following examples:

    1. select dbo.MyDistance(46.192131,21.274666,46.192131,21.274665)

    2. select dbo.MyDistance(46.192131,21.274666,46.192131,21.274666)

    Both examples will give the following error:

    Msg 3623, Level 16, State 1, Line 1

    An invalid floating point operation occurred.

    Keep improving it!

    I run both your query,here is no issue.see the attached..as the difference is too small so 0 is ans...if i cange your query to select dbo.Distance(46.192131,21.274666,46.292131,21.374666) then you can see distance.see the attached

  • krowley (6/12/2012)


    I noticed you were using and passing floats rather than the new spacial data types introduce in SQL Server 2008. Any reason why?

    it was for SQL Server2005.i have a small application from where a user can click on two different locations and this function return distance....as from google map we get Lat,Lon.that is why i have used this data type...

  • Makes sense if this was a SQL 2005 project. We still have a lot of stuff running on SQL 2005 as well.

  • Thanks for the script.

  • I should have had this in college.

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply