Skip to content

Instantly share code, notes, and snippets.

@tugberkugurlu
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tugberkugurlu/9683182 to your computer and use it in GitHub Desktop.
Save tugberkugurlu/9683182 to your computer and use it in GitHub Desktop.
Location Class which should be struct?
using System;
using System.Data.Spatial;
public class Location
{
public Location(double lat, double lng)
{
Latitude = lat;
Longitude = lng;
}
public Location(string wellKnownText)
{
if (wellKnownText == null)
{
throw new ArgumentNullException("wellKnownText");
}
DbGeography dbGeography = DbGeography.FromText(wellKnownText);
if (dbGeography.Latitude == null || dbGeography.Longitude == null)
{
throw new ArgumentException("wellKnownText (WKT) is not in a correct format.", "wellKnownText");
}
Latitude = dbGeography.Latitude.Value;
Longitude = dbGeography.Longitude.Value;
}
public double Latitude { get; private set; }
public double Longitude { get; private set; }
}
using System;
using System.Data.Spatial;
public struct SLocation
{
private readonly double _lat;
private readonly double _lng;
public SLocation(double lat, double lng)
{
_lat = lat;
_lng = lng;
}
public SLocation(string wellKnownText)
{
if (wellKnownText == null)
{
throw new ArgumentNullException("wellKnownText");
}
DbGeography dbGeography = DbGeography.FromText(wellKnownText);
if (dbGeography.Latitude == null || dbGeography.Longitude == null)
{
throw new ArgumentException("wellKnownText (WKT) is not in a correct format.", "wellKnownText");
}
_lat = dbGeography.Latitude.Value;
_lng = dbGeography.Longitude.Value;
}
public double Latitude { get { return _lat; } }
public double Longitude { get { return _lng; } }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment