Spatial Data not returning correct distance

  • I have the two following locations.

    They're both towns in Australia , State of Victoria

    Fitzroy,-37.798701, 144.978687

    Footscray,-37.799736, 144.899734

    After running geography::Point(Latitude, Longitude , 4326) on the latitude and longitude provided for each location, my Geography column for each row is populated with the following:

    Fitzroy, 0xE6100000010C292499D53BE642C0A7406667511F6240

    Footscray, 0xE6100000010C89B7CEBF5DE642C02D23F59ECA1C6240

    In my SQL Query, I have the following which works out the distance between both towns. Geo being my Geography column

    DECLARE @s-2 geography = 0xE6100000010C292499D53BE642C0A7406667511F6240 -- Fitzroy

    DECLARE @t geography = 0xE6100000010C89B7CEBF5DE642C02D23F59ECA1C6240 -- Footscray

    SELECT @S.STDistance(@t)

    The result I get is

    6954.44911927616

    I then looked at formatting this as in Australia we go by KM so after some searching I found two solutions one for Miles and the other KM

    So I changed Select statement to look like this

    select @S.STDistance(@t)/1000 -- format to KM

    My result is then

    6.95444911927616

    When I go to google maps and do a direction request between the locations provided above it says 10.2km (depending on traffic)

    Now I'm new to this spatial data within SQL, why would I get a different result from google maps?

    Also I would like to round this number so its easier to use within my where statement so I'm using Ceiling as shown here:

    SELECT CEILING(@s.STDistance(@t)/1000)

    Is ceiling the correct way to go?

    Reason I need to round this is because we are allowing the end user to search by radius so if they pass in 50km I will then say

    Where CEILING(@s.STDistance(@t)/1000) < 50

  • STDistance returns the straight line distance between two points (as the crow flies). GoogleMaps determines the distance by the sum of the lengths of sections of roads traveled on. Big difference between flying and driving.

  • Arrr I see!! that would explain a lot 🙂

    Also as you can see im rounding it would Ceiling be the best approach to round? or would it be wise using something different?

Viewing 3 posts - 1 through 2 (of 2 total)

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