Validate Latitude and Longitude With PHP

and like us on FB

The following functions will validate latitude and longitude data. The functions support a number of geo-related articles on our website Tag: maps.

Returns false if the value does not match.

The function validates again 6 decimal points (which you may obviously change). To force the six digits, and to further clean the input data, using $latitude = number_format($latitude, 6); (for both latitude and longitude) before validation may assist. In addition to truncating the decimals (or adding them), the function acts a little like the abs() function in that it’ll remove invalid characters. Because the decimals are required, the function will also add them if omitted.

We’ve also used the following expressions… essentially achieving the same thing.