[英]How to determine if Latitude is North or South, or Longitude West or East with Geolocator?
I'm building an Universal App in WinRT and am able to get the Latitude Longitude of my device using the Geolocator. 我正在WinRT中构建通用应用程序,并且能够使用Geolocator获取设备的纬度经度。 But for my input I also need the direction (North, South for Latitude and East West for Longitude).
但是对于我的输入,我还需要方向(北,南代表纬度,东西向代表经度)。
But how do I know if a Latitude or Longitude is within a specific direction? 但是,我怎么知道纬度或经度是否在特定方向上? Is there a build-in way, or what would be the calculation to do this?
是否有内置方法,或者执行此操作的计算方法是什么?
51.3705 to 51.3705N 51.3705至51.3705N
6.1724 to 6.1724E 6.1724至6.1724E
Geoposition GeoPosition = await GeoLocator.GetGeopositionAsync();
double Latitude = GeoPosition.Coordinate.Point.Position.Latitude;
double Longitude = GeoPosition.Coordinate.Point.Position.Longitude;
Kind regards, Niels 亲切的问候,尼尔斯
Instead of adding S/N or W/E to indicate the direction, you will get values from -90° (S) to 90° (N) and -180° (W) to 180° (E). 不用添加S / N或W / E来指示方向,您将获得-90°(S)至90°(N)和-180°(W)至180°(E)的值。 The docs doesn't explicitly specify which direction is positive, but what I've written here should be the most common convention.
文档未明确指定哪个方向是积极的,但是我在这里写的应该是最常见的约定。
Common sense :): 常识:):
private string ConvertLatitudeToGPS(double Latitude)
{
string Direction = "";
double UnformattedLatitude = Latitude;
if (Latitude > 0)
{
Direction = "N";
}
else
{
UnformattedLatitude = UnformattedLatitude * -1;
Direction = "S";
}
string GPSString = UnformattedLatitude.ToString("0.0000") + Direction;
return GPSString;
}
private string ConvertLongitudeToGPS(double Longitude)
{
string Direction = "";
double UnformattedLongitude = Longitude;
if (Longitude > 0)
{
Direction = "E";
}
else
{
UnformattedLongitude = UnformattedLongitude * -1;
Direction = "W";
}
string GPSString = UnformattedLongitude.ToString("0.0000") + Direction;
return GPSString;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.