What is the right type to store geolocation data about the user? Can I store accuracy in DbGeography?

asp.net-mvc asp.net-mvc-5.2 c# entity-framework-6 geolocation


I got LoginViewModel consisting of some double which define user location in the world:

public class LoginViewModel
    [Display(Name = "Email")]
    public string Email { get; set; }

    [Display(Name = "Password")]
    public string Password { get; set; }

    [Display(Name = "Remember me?")]
    public bool RememberMe { get; set; }

    public double Latitude { get; set; }
    public double Longitude { get; set; }
    public double Accuracy { get; set; }


later on I would like to store them in the database as user properties.

Should I store them as three doubles or as the other already defined type: presumably ICollection<DbGeography> or define ICollection of my own type consiting of Latitude, Longitude, Accuracy?

6/16/2015 1:29:58 PM

Popular Answer

Don't worry about how you will store them in the database, the ORM / datalayer can take care of storing and retrieving them from your database.

Think about how they will be used in your code. If they are always used together or are releated to each other, which in your case they are for both points, then you should create a type for them. A example of this is System.Drawing.Point you don't want to pass around x and y coordinates all the time and making sure the correct x and y coordinates are passed together. You just create a point and use it.

Finally I would personally use a decimal and not a double just is case you want to calculate distance or use the lat, long in calculation in the future. decimal vs double! - Which one should I use and when? is a good explanation if you are interested.

As SteveG said in his comment above, the best type to use would be the DbGeography which was added in .Net 4.5.

5/23/2017 11:43:42 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow