Check the latitude and longitude order in the WKT representation of a point in SQL when defining a point; they follow GEOGRAPHY::POINT(Latitude, Longitude, srid) :
SELECT GEOGRAPHY::Point(25.3132666,55.2994054 ,4326) .STDistance(GEOGRAPHY::Point(25.25434, 55.32820,4326)) as distance; //distance: 7142.94965953253
But when defining DBGeography in C # code, the order is different: "POINT(Longitude Latitude)"
String format = "POINT(55.32820 25.25434)"; DbGeography myLocation = DbGeography.PointFromText(format, 4326); var users = context.Users.Select(u => new { fullName = u.name, lat = u.location.Latitude, lng = u.location.Longitude, distance = myLocation.Distance(u.location) }).ToList(); //distance: 7142.949659532529
You should also check the places that were inserted into the Users table. Make sure they are inserted correctly when pasting. Otherwise, they will be somewhere else in the place of your Users
More
SELECT GEOGRAPHY::Point(25, 55 ,4326).Lat //25 DbGeography.PointFromText("POINT(25 55)", 4326).Latitude.Value //55 Microsoft.SqlServer.Types.SqlGeography.STPointFromText( new System.Data.SqlTypes.SqlChars("POINT(25 55)"), 4326).Lat.Value; //55
What is WKT and where did it come from? This is the W ell- K nown T ext representation of the various geometry types that OGC introduces into the Simple Feature Access , and all software developers are encouraged to follow to ensure compatibility. This specification shows us how to define point, linear (linear), polygon and some other types of geometry as text (WKT) and binary (WKB).
SQL Server does not fully comply with this specification, and we see the result of non-compliance with standards, causing such problems in different components of even the same company.
Hossein narimani rad
source share