-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
150 lines (132 loc) · 6.15 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<title>Last.fm Top Artists ... on a map!</title>
<link rel="stylesheet" href="css/main.css"/>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="js/lastfm.api.md5.js"></script>
<script type="text/javascript" src="js/lastfm.api.js"></script>
<script type="text/javascript" src="js/lastfm.api.cache.js"></script>
<script type="text/javascript">
//var cache = new LastFMCache();
var lastfm = new LastFM({
apiKey: 'c98d7b83a304204690e0c8bfb611b9a8',
apiSecret: '8bfc477cae6d757167214da62aa58efd',
// cache: cache
});
var map;
var marker;
var infowindow;
var geocoder;
function initialize() {
var latlng = new google.maps.LatLng(54, 2);
var options = {
zoom: 3,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), options);
geocoder = new google.maps.Geocoder();
google.maps.event.addListener(map, 'click', function (event) {
handleClick(event.latLng);
});
function handleClick(location) {
map.setCenter(location);
if (geocoder) {
geocoder.geocode({
'latLng': location
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results) {
for (var i = 0; i < results.length; i++) {
for (var j = 0; j < results[i].types.length; j++) {
if (results[i].types[j] == 'country') {
var country = results[i].address_components[0].long_name;
switch (country) {
case 'The Netherlands':
country = 'Netherlands';
break;
case 'Democratic Republic of the Congo':
country = 'Congo';
break;
case 'Vatican City':
country = 'Holy See';
break;
case 'South Korea':
country = 'Korea, Republic of';
break;
case 'North Korea':
country = "Korea, Democratic People's Republic of";
break;
}
lastfm.geo.getTopArtists({
country: country
}, {
success: function (data) {
var a = data.topartists.artist[0];
var img_url;
var img_idx;
for(var i = 0; i < a.image.length; i++) {
if (a.image[i].size == 'extralarge') {
img_idx = i;
break;
}
}
var m = '<div class="info-box"><h3>' + country + ' loves ' + a.name + '</h3>'
+ '<p><a href="' + a.url + '"><img src="' + a.image[img_idx]["#text"] + '"/></a></p>'
+ '</div>';
if (marker) {
marker.setMap(null);
}
marker = new google.maps.Marker({
position: location,
map: map,
title: country
});
if (infowindow) {
infowindow.close();
}
infowindow = new google.maps.InfoWindow({
content: m
});
infowindow.open(map, marker);
},
error: function (code, message) {
alert(code + ': ' + message);
}
});
}
}
}
}
} else {
if (marker) {
marker.setMap(null);
}
marker = new google.maps.Marker({
position: location,
map: map,
title: country
});
if (infowindow) {
infowindow.close();
}
infowindow = new google.maps.InfoWindow({
content: '<div class="info-box"><h3>Sorry!</h3><p>Not sure where that is.<p></div>'
});
infowindow.open(map, marker);
}
});
}
}
}
</script>
</head>
<body onload="initialize()">
<h1>Last.fm top artists ... on a map! <small>[Click a country!]</small></h1>
<h2>by <a href="http://mrben.co.uk/">Ben Tappin</a></h2>
<div id="map_canvas" style="width:100%; height:78%;"></div>
<p>Made with <a href="http://www.last.fm/api">Last.fm</a>, <a href="http://code.google.com/apis/maps/documentation/javascript/">Google Maps</a> and <a href="http://github.com/fxb/javascript-last.fm-api">fxb's javascript-last.fm-api.</a></p>
</body>
</html>