-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.php
More file actions
105 lines (96 loc) · 2.4 KB
/
Program.php
File metadata and controls
105 lines (96 loc) · 2.4 KB
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
<HTML>
<HEAD></HEAD>
<BODY>
<?php
$fbresponsep = $_GET['fbresp'];
$atoken = $_GET['atoken'];
if($fbresponsep == 'connected')
{
?>
<script src="mapsapikeyurl&sensor=false">
</script>
<script>
var ListofFriends = <?php $postdata = file_get_contents("https://graph.facebook.com/me?access_token=" . $atoken . "&fields=friends.fields(location,name)");
echo $postdata;
?>;
//console.log(locations);
function transformArr(orig) {
var newArr = [],
types = {},
newItem, i, j, cur;
for (i in orig) {
cur = orig[i];
if (!(cur.location in types)) {
types[cur.location] = {location: cur.location, names: []};
newArr.push(types[cur.location]);
}
types[cur.location].names.push(cur.name);
}
return newArr;
}
function initialize()
{
geocoder = new google.maps.Geocoder();
var mapProp = {
center:new google.maps.LatLng(51.508742,-0.120850),
zoom:5,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map=new google.maps.Map(document.getElementById("googleMap")
,mapProp);
console.log ("Filterin to only list friends");
var data = ListofFriends['friends']['data'];
var curlocknown = {};
var skip = 0
console.log(data);
for(var i in data)
{
if(typeof data[i].location != "undefined")
{
var tmp = {name:data[i].name,location:data[i].location["name"]};
curlocknown[(i-skip)] = tmp;
}else
{
skip += 1;
}
}
var locationsGrouped = transformArr(curlocknown)
for(locnumb in locationsGrouped)
{
//TODO: Add locatio cache to db here.
codeAddress(locationsGrouped[locnumb].location, locationsGrouped[locnumb].names)
}
console.log(locationsGrouped);
}
function codeAddress(address, name)
{
geocoder.geocode( {address:address}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
map.setCenter(results[0].geometry.location);//center the map over the result
//place a marker at the location
//a
console.log(results[0].geometry.location);
var marker = new google.maps.Marker(
{
map: map,
position: results[0].geometry.location,
title: name.join()
});
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<div id="googleMap" style="width:500px;height:380px;"></div>
<?php
}
else
{
}
?>
</BODY>
</HTML>