Google Maps and MSSQL seem to disagree on how to calculate the distance/length of a polyline/linestring using SRID 4326.
MSSQL:
SELECT geography::STGeomFromText('LINESTRING(-98.78 39.63,2.98 27.52)', 4326).STLength()
Result: 9030715.95721209
Then Google Maps:
http://jsbin.com/niratiyojo/1/
Result: 9022896.239500616
At first I thought it was just a different radius of earth measure so I played around with that and it turned out to be more.
I need my JavaScript interface to match what MSSQL would report to remain consistent and accurate. Where or how can I find how MSSQL calculates their STLength()
and can it be replicated in JavaScript?
Update:
I realized if I do
SELECT GEOGRAPHY::STGeomFromText('LINESTRING(-98.78 39.63,2.98 27.52)', 104001).STLength() * 6378137
Then MSSQL returns 9022896.23950062
The new SRID in MSSQL :
New “Unit Sphere” Spatial Reference ID The default spatial reference ID (SRID) in SQL Server 2012 is 4326, which uses the metric system as its unit of measurement. This SRID also represents the true ellipsoidal sphere shape of the earth. While this representation is most accurate, it’s also more complex to calculate precise ellipsoidal mathematics. SQL Server 2012 offers a compromise in speed and accuracy, by adding a new spatial reference id (SRID), 104001, which uses a sphere of radius 1 to represent a perfectly round earth.
So the problem is that Google Maps does not use a true ellipsoidal sphere in calculations. I am looking for a javascript function that gets 9030715.95721209
as witnessed.
I tried Vincenty direct formula here: http://jsbin.com/noveqoqepa/1/edit?html,js,console and while it's closer I still cannot match MSSQL
Edit 2:
I was able to find the measurements it uses:
SridList._sridList.Add(4326, new SridInfo(4326, "EPSG", 4326, "GEOGCS[\"WGS 84\", DATUM[\"World Geodetic System 1984\", ELLIPSOID[\"WGS 84\", 6378137, 298.257223563]], PRIMEM[\"Greenwich\", 0], UNIT[\"Degree\", 0.0174532925199433]]", "metre", 1.0, 6378137.0,
6356752.314));
but seemingly plugging those into Vincenty yield no luck.