-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdirections.php
64 lines (53 loc) · 2.3 KB
/
directions.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
<?php
// This is just for my examples
require( '_system/config.php' );
$relevant_code = array(
'\PHPGoogleMaps\Service\DrivingDirections',
'\PHPGoogleMaps\Service\WalkingDirections',
'\PHPGoogleMaps\Service\BicyclingDirections',
'\PHPGoogleMaps\Service\Directions',
'\PHPGoogleMaps\Service\DirectionsDecorator'
);
// Autoloader stuff
require( '_system/autoload.php' );
// Create a new map and set some options
$map = new \PHPGoogleMaps\Map;
$map->setCenter( 'USA' );
$map->setZoom( 3 );
// If origin and destination are set add directions
if ( isset( $_GET['origin'], $_GET['destination'] ) && strlen( $_GET['origin'] ) && strlen( $_GET['destination'] ) ) {
try {
$directions = new \PHPGoogleMaps\Service\DrivingDirections( $_GET['origin'], $_GET['destination'] );
if ( isset( $_GET['waypoint'] ) && $_GET['waypoint'] != '' ) {
$directions->addWaypoint( $_GET['waypoint'] );
}
$map->addObject( $directions );
}
catch ( \PHPGoogleMaps\Service\GeocodeException $e ) {
$error = $e;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Directions - <?php echo PAGE_TITLE ?></title>
<link rel="stylesheet" type="text/css" href="_css/style.css">
<?php $map->printHeaderJS() ?>
<?php $map->printMapJS() ?>
</head>
<body>
<h1>Directions</h1>
<?php require( '_system/nav.php' ) ?>
<form action="">
<label>Origin:</label><br><input type="text" name="origin" value="<?php echo isset( $_GET['origin'] ) ? $_GET['origin'] : '' ?>"><br>
<label>Waypoint:</label><br><input type="text" name="waypoint" value="<?php echo isset( $_GET['waypoint'] ) ? $_GET['waypoint'] : '' ?>"><br>
<label>Destination:</label><br><input type="text" name="destination" value="<?php echo isset( $_GET['destination'] ) ? $_GET['destination'] : '' ?>">
<input type="submit" value=" Get Directions ">
</form>
<p><?php if( isset( $directions ) ): ?><strong><?php echo $_GET['origin'] ?></strong> to <strong><?php if( $_GET['waypoint'] != '' ): ?><?php echo $_GET['waypoint'] ?></strong> to <?php endif; ?><strong><?php echo $_GET['destination'] ?></strong><?php endif; ?></p>
<?php if( isset( $error ) ): ?><p class="error">Unable to geocode "<?php echo $error->location ?>": <?php echo $error->error ?></p><?php endif; ?>
<?php $map->printMap() ?>
</body>
</html>