-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgeolocation.php
62 lines (46 loc) · 1.8 KB
/
geolocation.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
<?php
// This is for my examples
require( '_system/config.php' );
// Autoload stuff
require( '_system/autoload.php' );
$map = new \PHPGoogleMaps\Map;
//
$marker = \PHPGoogleMaps\Overlay\Marker::createFromUserLocation( array( 'geolocation_high_accuracy' => true, 'geolocation_timeout' => 10000 ) );
$map->addObject( $marker );
// If you want to set geolocation options you must call enableGeolocation() explicitly
// Otherwise it will be called for you when you use geolocation functions
$map->enableGeolocation( 5000, true );
$map->centerOnUser( \PHPGoogleMaps\Service\Geocoder::geocode('New York, NY') );
$map->setWidth('500px');
$map->setHeight('500px');
$map->setZoom(16);
// Set the callbacks
$map->setGeolocationFailCallback( 'geofail' );
$map->setGeolocationSuccessCallback( 'geosuccess' );
// Set the loading content. This will display while the browser geolocates the user.
$map->setLoadingContent('<div style="background:#eee;height:300px;padding: 200px 0 0 0;text-align:center;"><img src="_images/loading.gif" style="display:block; margin: auto;"><p>Locating you...</p></div>');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Geolocation - <?php echo PAGE_TITLE ?></title>
<link rel="stylesheet" type="text/css" href="_css/style.css">
<?php $map->printHeaderJS() ?>
<?php $map->printMapJS() ?>
<script type="text/javascript">
function geofail() {
alert( 'geolocation failed' );
}
function geosuccess() {
alert( 'geolocation succeeded' );
}
</script>
</head>
<body>
<h1>Geolocation</h1>
<?php require( '_system/nav.php' ) ?>
<p>This example finds your location and centers the map on it. It also uses map::setLoadingContent() to display a loading message to the user.</p>
<?php $map->printMap() ?>
</body>
</html>