[postgis-users] Comparing St_Distance() with Google API

James David Smith james.david.smith at gmail.com
Wed Jul 24 04:09:30 PDT 2013


Hi there everyone,

I've been messing about using the Google Directions API thing
recently, and came across some odd results. Code to demonstrate is
below.

Essentially the distance between two points using PostGIS is 18
metres, yet when I translate the points to Lat/Long and then stick
them in the Google API the distance comes out as 1 metre.

Does anyone have any thoughts on this?

Thanks

James

--------------------------------------------------------------------
-- Calculate a distance between two points using SRID 27700 (OSGB36):

SELECT St_Distance(
St_SetSRID(ST_makePoint(531058, 178463), 27700) ,
St_SetSRID(ST_makePoint(531041, 178455), 27700)
)

RESULT = 18.7882942280559  (I presume metres)
---------------------------------------------------------------------
-- Now calculte a distance between two points using SRID 4326 (WGS84):

SELECT St_Distance(
St_Transform(St_SetSRID(ST_makePoint(531058, 178463), 27700), 4326),
St_Transform(St_SetSRID(ST_makePoint(531041, 178455), 27700), 4326)
)

RESULT = 0.000256838311729703 (I presume degrees)

---------------------------------------------------------------------
-- Now calculate the distance using the Google Directions API using
the Lat/Lon values:

http://maps.googleapis.com/maps/api/directions/json?origin=51.4899343224464%20-0.113689479559085&destination=51.4898663658699%20-0.113937164484113&mode=walking&sensor=false&units=metric

RESULT = "1 m"


More information about the postgis-users mailing list