SQL Server: How to validate Latitude & Longitude value is valid

Hello Folks,

I've one table which contains Latitude & Longitude for each record.

Is there any ways to validate Latitude & Longitude value valid or not?

Best Regards
LVL 5
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Senior Software EngineerCommented:
The latitude must be a number between -90 and 90 and the longitude between -180 and 180.
So, you can create check constraints on your fields.
``````create table x (
id int not null,
latitude float CHECK (latitude > -90 and latitude < 90),
longitude float CHECK (longitude > -90 and longitude < 90))
``````
0
Author Commented:
Should it be >= -90 and <=90 i.e. greater than equal to 90 and less than equal to 90?

Apart, do you have any URL for this rule?
0
Senior Software EngineerCommented:
No, I don't have. But you can get many if you simply type valid latitude longitude values on google.
Here is the fixed check constraints for that.

``````create table x (
id int not null,
latitude float CHECK (latitude >= -90 and latitude <= 90),
longitude float CHECK (longitude >= -180 and longitude <= 180))
``````
0
Commented:
Apart, do you have any URL for this rule?
Think about it for a minute:
By definition Latitude is the North South angle of the point between the Equator and the poles, therefore -90 to +90.
Longitude is the East West position based on an arbitrary base point (Greenwich) and therefore -180 to +180.
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
Thank you
0
Commented:
Walter Ritzel,

Did not intend to steal the points from your very valid answer.

Anthony
0
Senior Software EngineerCommented:
Anthony Perkins, no problem at all, man.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.