How to validate latitude and longitude
The latitude must be a number between -90 and 90 and the longitude between -180 and 180.
Here are the functions to validate it in JavaScript.
- Latitude must be a number between -90 and 90
const isLatitude = num => isFinite(num) && Math.abs(num) <= 90;
- Longitude must a number between -180 and 180
const isLongitude = num => isFinite(num) && Math.abs(num) <= 180;