Skip to content

Instantly share code, notes, and snippets.

Created June 5, 2017 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/99e718375ec9ad9bbdd6d4c366a40752 to your computer and use it in GitHub Desktop.
Save anonymous/99e718375ec9ad9bbdd6d4c366a40752 to your computer and use it in GitHub Desktop.
[PHP] Latitude and Longitude in PHP: A Few Useful Practices
<?php
$latitude = $_REQUEST['acme-demo-latitude'];
$longitude = $_REQUEST['acme-demo-longitude'];
<?php
$latitude = filter_var(
$_REQUEST['acme-demo-latitude'],
FILTER_SANITIZE_NUMBER_FLOAT
);
$longitude = filter_var(
$_REQUEST['acme-demo-longitude'],
FILTER_SANITIZE_NUMBER_FLOAT
);
<?php
$latitude = floatval(
filter_var(
$_REQUEST['acme-demo-latitude'],
FILTER_SANITIZE_NUMBER_FLOAT
)
);
$longitude = floatval(
filter_var(
$_REQUEST['acme-demo-latitude'],
FILTER_SANITIZE_NUMBER_FLOAT
)
);
<?php
// Return false...
if ( ! ( is_float( $latitude ) && is_float( $longitude ) ) ) {
return false;
}
// Or throw an exception...
if ( ! ( is_float( $latitude ) && is_float( $longitude ) ) ) {
throw new Exception('Latitude and longitude are not valid floating point values.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment