This repository has been archived by the owner on Sep 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
114 lines (103 loc) · 3.42 KB
/
index.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
require_once('config.php');
require_once(CLIENT);
session_start();
// Setup API client and get access token
$oauth = PodioOAuth::instance();
$baseAPI = PodioBaseAPI::instance(CLIENT_ID, CLIENT_SECRET);
// Obtain access token and init API class
if (!isset($_SESSION['access_token'])) {
$oauth->getAccessToken('password', array('username' => USERNAME, 'password' => PASSWORD));
$api = new PodioAPI();
$_SESSION['gmap_access_token'] = $oauth->access_token;
$_SESSION['gmap_refresh_token'] = $oauth->refresh_token;
}
else {
$oauth->access_token = $_SESSION['gmap_access_token'];
$oauth->refresh_token = $_SESSION['gmap_refresh_token'];
$api = new PodioAPI();
}
// Get all items in Location Scouting app.
// Find the address and convert to JSON for outputting
// in the JavaScript below.
$items = $api->item->getItems(APP_ID, 100, 0, 'title', 0);
$markers = array();
foreach ($items['items'] as $item) {
$marker = array(
'title' => $item['title'],
'description' => '',
);
foreach ($item['fields'] as $field) {
if ($field['type'] == 'location') {
$marker['address'] = $field['values'][0]['value'];
}
if ($field['type'] == 'text') {
$marker['description'] = $field['values'][0]['value'];
}
}
$markers[] = $marker;
}
?><!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0px; padding: 0px; font-family: Arial, sans-serif; font-size: 12px; }
h1 { font-size: 1.5em; margin: 0 0 0.3em 0; }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
var map;
var geocoder;
var podio_markers = <?php print json_encode($markers); ?>;
function dropPin() {
if (podio_markers.length > 0) {
geocoder.geocode( { 'address': podio_markers[0]['address']}, function(results, status) {
var current_marker = podio_markers.shift();
if (status == google.maps.GeocoderStatus.OK) {
if (podio_markers.length == 0) {
map.setCenter(results[0].geometry.location);
}
// Add marker
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
title: current_marker['title']
});
// Add info window
var infowindow = new google.maps.InfoWindow({
content: '<div id="content"><h1 id="firstHeading" class="firstHeading">'+current_marker['title'] +'</h1>'+ current_marker['description']+'</div>',
maxWidth: 300
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
} else {
console.log("Geocode was not successful for the following reason: " + status);
}
dropPin();
});
}
}
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(55.705015,12.556601);
var myOptions = {
zoom: 14,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
dropPin();
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>