Skip to content

Instantly share code, notes, and snippets.

@filippomangione
Last active June 24, 2019 17:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save filippomangione/6f9d78e955ae2f228d28 to your computer and use it in GitHub Desktop.
Save filippomangione/6f9d78e955ae2f228d28 to your computer and use it in GitHub Desktop.
A simple function to validate latitude and longitude in php.
<?php
function validateGeoCoords($lat=null,$lng=null) {
return (trim($lat,'0') == (float)$lat) && (trim($lng,'0') == (float)$lng);
}
@philippzentner
Copy link

This may be a shorter validation as here (http://altafphp.blogspot.de/2013/11/validate-latitude-and-longitude-with.html) but not a good one as you do not proof the possible range of latitude (+- 90) and longitude (+-180)

@zeroiszero
Copy link

its not the correct in http://altafphp.blogspot.de/2013/11/validate-latitude-and-longitude-with.html
but check the comment under it, that might be correct.... :)

Copy link

ghost commented Oct 29, 2017

To implement validation for latitude and longitude values we can write a logic that, latitude must be a number between -90 and 90 and the longitude between -180 and 180 degree inclusive. Yo can get the free source code from here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment