-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgeocoding.php
50 lines (39 loc) · 1.15 KB
/
geocoding.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
<?php
// This is just for my examples
require( '_system/config.php' );
$relevant_code = array(
'\PHPGoogleMaps\Service\Geocoder',
'\PHPGoogleMaps\Service\GeocodeError',
'\PHPGoogleMaps\Service\GeocodeResult',
'\PHPGoogleMaps\Service\GeocodeException'
);
// Autoloader stuff
require( '_system/autoload.php' );
$map = new \PHPGoogleMaps\Map;
// Geocode a location and set the center of the map
// If geocode fails fallback to a different map center
// If no center is set the map will not display
$geocode = \PHPGoogleMaps\Service\Geocoder::geocode( 'San Diego, CA' );
if ( $geocode instanceof \PHPGoogleMaps\Service\GeocodeResult ) {
// Set center of map to geocoded location
$map->setCenter( $geocode );
}
else {
$map->setCenter( 'New York, NY' );
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Geocoding - <?php echo PAGE_TITLE ?></title>
<link rel="stylesheet" type="text/css" href="_css/style.css">
<?php $map->printHeaderJS() ?>
<?php $map->printMapJS() ?>
</head>
<body>
<h1>Geocoding</h1>
<?php require( '_system/nav.php' ) ?>
<?php $map->printMap() ?>
</body>
</html>