p_loc.html
7.08 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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=<sc>, initial-scale=1.0">
<link rel="Stylesheet" href="../../assets/css/p_loc.css">
<title>Photo classification by location</title>
<style></style>
</head>
<body>
<div class='all'>
<div class='top'>
<div class='title'>
<img src="../../assets/img/photo_loc.png" onclick="history.go(-1)" class="float_left" title="Back to photo menu">
</div>
</div>
<div class='content'>
<div id="main">
<h1 style="margin-top:250px; color:dimgray; text-align: center;">지도의 마크를 클릭해 해당 사진과 인근 위치에서 찍힌 사진을 확인하세요.</h1>
</div>
<div id="explanation">
</div>
<div id="map"></div>
</div>
</div>
<script type=text/javascript>
var mysql = require('mysql');
//mysql 연동
var connection = mysql.createConnection({
user:'root',
password:'1234',
database : 'dataextraction'
})
connection.connect();
var list;
function initMap() {
connection.query('SELECT * FROM photo where latitude is not null', function(error, results, fields){
if(error){
}
else{
list = results;
var first_p = {lat: Number(list[0].latitude), lng: Number(list[0].longitude)};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 8,
center: first_p
});
list.forEach(element => {
var latlng = {lat : Number(element.latitude), lng : Number(element.longitude)};
var time = new Date(Number(element.date_added)*1000);
var path = new String();
path = element.path;
var num = path.indexOf("DCIM");
var folder_path = new String();
folder_path = "../../photos/" + path.substring(num);
var address = new String();
var geocoder = new google.maps.Geocoder;
geocoder.geocode({'location' : latlng}, function(results, status){
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: element.display_name
});
if(status == 'OK'){
if(results[0]){
address = results[0].formatted_address;
var contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">'+element.title+'</h1>'+
'<div id="bodyContent">'+
'<p><b>'+element.display_name+'</b></p><p><b>'+time+'</b </p><p>'+
results[0].formatted_address+'</p></div>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString,
maxWidth: 300
});
marker.addListener('click', function() {
infowindow.open(map, marker);
p_group(element);
});
}
else{
var contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">'+element.title+'</h1>'+
'<div id="bodyContent">'+
'<p><b>'+element.display_name+'</b></p><p><b>'+time+'</b </p><p>('+
latlng.lat+','+latlng.lng+'</p></div>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString,
maxWidth: 300
});
marker.addListener('click', function() {
infowindow.open(map, marker);
p_group(element);
});
}
}
else{
var contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">'+element.title+'</h1>'+
'<div id="bodyContent">'+
'<p><b>'+element.display_name+'</b></p><p><b>'+time+'</b </p><p>('+
latlng.lat+','+latlng.lng+')</p></div>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString,
maxWidth: 300
});
marker.addListener('click', function() {
infowindow.open(map, marker);
p_group(element);
});
}
});
});
}
})
}
function p_group(photo){
const main = document.getElementById('main');
var path = new String();
path = photo.path;
var num = path.indexOf("DCIM");
var folder_path = new String();
folder_path = "../../photos/" + path.substring(num);
var myHTML = '';
myHTML += '<div class="p"><img src="'+folder_path+'"></div>';
list.forEach(element=>{
if(element.title != photo.title){
var hor = photo.latitude - Number(element.latitude);
hor *=111;
var ver = photo.longitude - Number(element.longitude);
ver *=88;
if(((hor*hor) + (ver*ver))<=25){
main.innerHTML = "<p>Bye</p>"
var path2 = new String();
path2 = element.path;
var num2 = path2.indexOf("DCIM");
var folder_path2 = new String();
folder_path2 = "../../photos/" + path2.substring(num2);
myHTML += '<div class="ex"><img id="ex" src="'+folder_path2+'"></div>';
}
}
});
main.innerHTML = myHTML;
document.getElementById('explanation').innerHTML = "<h1>[ "+photo.display_name+" ]</h1><h1>5km 인근 사진 모음</h1>"
}
</script>
<script async defer
src="http://maps.google.com/maps/api/js?key=API_KEY&callback=initMap&sensor=true">
</script>
</body>
</html>