Calculate distance between two GPS points (SQL Server)


In my last post, I found out how to check if a GPS point resides an area. In addition, I need to calculate the distance between two GPS points. Again, I am using samples from my neighborhood. The distance between train stations in Fredrikstad and Sarpsborg. Now I will only calculate the distance air wise, but this can be extended to use Bing data services to calculate how far this distance is in walking, driving and maybe by travelling by train.

blog_bing_distance

Code:

DECLARE @p3 GEOGRAPHY;
DECLARE @p4 GEOGRAPHY;
SET @p3 = geography::Parse('POINT(59.209111 10.950330)');
SET @p4 = geography::Parse('POINT(59.286441 11.116841)');
SELECT @p3.STDistance(@p4) as Meters1;

Happy coding….

Advertisements

2 thoughts on “Calculate distance between two GPS points (SQL Server)

  1. How i will extract the driving distance b/w points using sql server.
    This distance is b/w two points but not driving distance.

    • I have never done it myself, but I think you must use a map service and find nearest road accordingly. Go to the google map developer pages for more information.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s