This repository has been archived by the owner on Nov 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
116 lines (97 loc) · 3.57 KB
/
index.html
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
115
116
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Photos near you</title>
<script src="js/instajam/dist/instajam.js"></script>
<script>
'use strict';
var photoWrapper, photoRange, loadingMsg;
document.addEventListener("DOMContentLoaded", function() {
// global.
photoWrapper = document.getElementById('photo-wrapper');
photoRange = document.getElementById('range');
loadingMsg = document.getElementById('loading-msg');
photoRange.onchange = redisplay;
redisplay();
});
var redisplay = function()
{
var posError;
photoWrapper.innerHTML = '';
loadingMsg.style.display='block';
if ("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition(geoLocSuccessHandler,
geoLocFailHandler);
}
else {
posError = {message: 'Your browser does not support geo location, please upgrade.'};
geoLocFailHandler(posError);
}
}
var geoLocSuccessHandler = function(pos) {
requestNewPhotos(pos.coords.latitude, pos.coords.longitude, updateDisplay);
}
var geoLocFailHandler = function(posError) {
alert(posError.message);
}
var requestNewPhotos = function(lat, lng, callback) {
var distance, IG = new Instajam({
clientID: '4f9b5392c55b40f3baab4d4dee8bc749',
});
distance = range.value * 1000;
IG.media.search({lat:lat, lng: lng, distance: distance}, callback);
}
var updateDisplay = function (response) {
console.log(response);
loadingMsg.style.display='none';
if (response.meta.code === 200) {
showConnectionWarning(false);
response.data.forEach(displayMedia);
}
else {
showConnectionWarning(true);
}
};
var displayMedia = function (media) {
var elImg = document.createElement("img");
elImg.src = media.images.low_resolution.url;
elImg.height = media.images.low_resolution.height;
elImg.width = media.images.low_resolution.width;
var title = document.createTextNode("View ");
if (media.caption != null) {
title.appendData(media.caption.text);
}
title.appendData(" on Instagram");
var elLink = document.createElement("a");
elLink.href = media.link;
elLink.title = title.data;
elLink.appendChild(elImg);
photoWrapper.appendChild(elLink);
}
var showConnectionWarning = function(show)
{
}
</script>
<style type="text/css">
#controls {margin-bottom:1em;}
#small-print {font-size: 0.7em;}
</style>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0" />
</head>
<body>
<h1>Photos near you</h1>
<div id="controls">
<label for="range">Distance (km)</label>
<!-- instagram max is 5km -->
<input id ="range" type="number" step="any" min="0.1" max="5" value="1" />
</div>
<p id="loading-msg">
Loading...
</p>
<div id="photo-wrapper">
</div>
<p id="small-print">All photos are provided by instagram and are the property of their owners.
I don't collect any information from you, github and instagram might.</p>
</body>
</html>