You can use example below to validate latitude and longitude with preg_match function.


Example


/*
* The valid range:
* - in degrees
* - latitude -90 and +90
* - longitude -180 and +180
* - in decimals
* - latitude precision=10, scale=8
* - longitude precision=11, scale=8
*/
function isGeoValid($type, $value)
{
$pattern = ($type == 'latitude')
? '/^(\+|-)?(?:90(?:(?:\.0{1,8})?)|(?:[0-9]|[1-8][0-9])(?:(?:\.[0-9]{1,8})?))$/'
: '/^(\+|-)?(?:180(?:(?:\.0{1,8})?)|(?:[0-9]|[1-9][0-9]|1[0-7][0-9])(?:(?:\.[0-9]{1,8})?))$/';

if (preg_match($pattern, $value)) {
return 'VALID '.$type;
} else {
return 'INVALID '.$type;
}
}

echo isGeoValid('latitude', '-90.00000000');
echo PHP_EOL;
echo isGeoValid('longitude', '-180.00000000');