简体   繁体   中英

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. 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

6.1724 to 6.1724E

Geoposition GeoPosition = await GeoLocator.GetGeopositionAsync();
double Latitude = GeoPosition.Coordinate.Point.Position.Latitude;
double Longitude = GeoPosition.Coordinate.Point.Position.Longitude;

Kind regards, Niels

Have a look here .

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). 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;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM