-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexamples.php
85 lines (79 loc) · 2.15 KB
/
examples.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use Frostybee\Geobee\Calculator;
/*
* Calculate distance from downtown Montreal to Laval
* From: Ville-Marie (postal code area: H3A)
* Latitude/Longitude: 45.4987, -73.5703
* To: Laval (postal code area: H7T)
* Latitude/Longitude: 45.55690, -73.7480
*/
$from_latitude = 45.4987;
$from_longitude = -73.5703;
$to_latitude = 45.55690;
$to_longitude = -73.7480;
$calculator = new Calculator();
$distance = $calculator->calculate(
$from_latitude,
$from_longitude,
$to_latitude,
$to_longitude
)->to('km');
echo '<pre>';
echo '---------- <br>';
echo sprintf(
"The distance between point(%f, %f) and point(%f, %f) is %f km",
$from_latitude,
$from_longitude,
$to_latitude,
$to_longitude,
$distance
);
echo '<br>';
// Distance in meters.
$distance = $calculator->calculate(
$from_latitude,
$from_longitude,
$to_latitude,
$to_longitude
)->getDistance();
echo '---------- <br>';
echo sprintf(
"The distance between point(%f, %f) and point(%f, %f) is %f m",
$from_latitude,
$from_longitude,
$to_latitude,
$to_longitude,
$distance
);
echo '<br>';
// Examples of single conversions:
$distance = $calculator->to('mi', 3, false); // False to round UP, true, round down.
echo '---------- <br>';
echo sprintf(
"The distance between point(%f, %f) and point(%f, %f) is %f mi",
$from_latitude,
$from_longitude,
$to_latitude,
$to_longitude,
$distance
);
echo '<br>';
echo '---------- <br>';
echo 'Rounded distance: ';
echo $calculator->to('km', 2, false); // False to round UP, true, round down.
echo '<br>';
echo '---------- <br>';
// Convert to all supported length units.
echo 'Distance converted to all units of lengths<br>';
$results = $calculator->toAll(2, true);
//echo $calculator->to('nm', 5, false);
var_dump($results);
// Convert to multiple (one or more).
$results = $calculator->toMany(['km', 'mi'], 3, true);
echo '---------- <br>';
echo 'Distance converted to all units of lengths<br>';
var_dump($results);
// Test validation method.
$is_valid = $calculator->is_coordinate($from_latitude, $from_longitude);
var_dump($is_valid);