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 6
MohitPanditAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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

Walter RitzelSenior 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))

Open in new window

MohitPanditAuthor 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?
Walter RitzelSenior 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))

Open in new window

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Anthony PerkinsCommented:
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

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

Start your 7-day free trial
MohitPanditAuthor Commented:
Thank you
Anthony PerkinsCommented:
Walter Ritzel,

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

I am sorry about that.

Anthony
Walter RitzelSenior Software EngineerCommented:
Anthony Perkins, no problem at all, man.
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.