Created
November 20, 2014 22:26
-
-
Save RedTahr/fbfe776204eb8d5de949 to your computer and use it in GitHub Desktop.
Common helpers in Xamarin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://developer.xamarin.com/recipes/ios/content_controls/map_view/display_a_location/ | |
/// <summary>Converts miles to latitude degrees</summary> | |
public static double MilesToLatitudeDegrees(double miles) { | |
double earthRadius = 3960.0; // in miles | |
double radiansToDegrees = 180.0 / Math.PI; | |
return (miles / earthRadius) * radiansToDegrees; | |
} | |
/// <summary>Converts miles to longitudinal degrees at a specified latitude</summary> | |
public static double MilesToLongitudeDegrees(double miles, double atLatitude) { | |
double earthRadius = 3960.0; // in miles | |
double degreesToRadians = Math.PI / 180.0; | |
double radiansToDegrees = 180.0 / Math.PI; | |
// derive the earth's radius at that point in latitude | |
double radiusAtLatitude = earthRadius * Math.Cos(atLatitude * degreesToRadians); | |
return (miles / radiusAtLatitude) * radiansToDegrees; | |
} | |
/// <summary>Converts kilometres to latitude degrees</summary> | |
public static double KilometresToLatitudeDegrees(double kms) { | |
double earthRadius = 6371.0; // in kms | |
double radiansToDegrees = 180.0 / Math.PI; | |
return (kms / earthRadius) * radiansToDegrees; | |
} | |
/// <summary>Converts kilometres to longitudinal degrees at a specified latitude</summary> | |
public static double KilometresToLongitudeDegrees(double kms, double atLatitude) { | |
double earthRadius = 6371.0; // in kms | |
double degreesToRadians = Math.PI / 180.0; | |
double radiansToDegrees = 180.0 / Math.PI; | |
// derive the earth's radius at that point in latitude | |
double radiusAtLatitude = earthRadius * Math.Cos(atLatitude * degreesToRadians); | |
return (kms / radiusAtLatitude) * radiansToDegrees; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void ParseGPS(string gpsLocation, out double latitude, out double longitude) { | |
int commaPos = gpsLocation.IndexOf(',', 1); | |
Double.TryParse(gpsLocation.Substring(0, commaPos), out latitude); | |
Double.TryParse(gpsLocation.Substring(commaPos + 1, gpsLocation.Length - commaPos - 1), out longitude); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment