Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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
You can’t perform that action at this time.