windows runtime - Distance and other stuff between two Location in C# / WinRT -
how can distance between 2 location
in c#? nice direction between 2 locations if have compass value of device.
is there api this?
it depends. mean location?
case 1: when location geographic point (latitude, longitude)
you need go through spherical geometry. in fact should create calculation on sphere (or ellipsoid or other spheroids). best way avoid doing such complicated calculation utilize microsoft.sqlserver.types.dll
(v.10 or v.11). if have sql server 2012 (or 2008) installed on system, can find somewhere (otherwise may download web):
"c:\program files\microsoft sql server\110\shared\microsoft.sqlserver.types.dll"
then using dll can declare 2 sqlgeography
type , phone call stdistance()
method , done correctly. (remember there lost of issue here, i'm not going complicate more this). here code:
sqlgeography p1 = sqlgeography.stpointfromtext(new system.data.sqltypes.sqlchars("point( lat1, long1)"), 4326); // srid of wgs84: 4326 sqlgeography p2 = sqlgeography.stpointfromtext(new system.data.sqltypes.sqlchars("point( lat2, long2)"), 4326); // srid of wgs84: 4326 double distance = p1.stdistance(p2).value;
case 2: when location simple local 2d point (x, y) on plane
in case can utilize famous formula calculate distance:
double distance = math.sqrt(dx*dx + dy*dy); //dx , dy difference of x , y of 2 points
c# windows-runtime windows-store-apps
No comments:
Post a Comment