map.ejs
6.45 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<html>
<head>
<title><%= title %></title>
<link rel='stylesheet' href='/stylesheets/style.css'/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBTR69UvS1403rvBcM64_8nlzpKLv23RIE&libraries=places"></script>
<script>
function addShop(id) {
var placeid = $(id).attr('id');
var placename = $(id).attr('name');
var placeaddress = $(id).attr('address');
$('input[name=useremail]').val('<%=user.email%>');
$('input[name=id]').val(placeid);
$('input[name=title]').val(placename);
$('input[name=address]').val(placeaddress);
console.log($('input[name=id]').val());
$('form[name=shop]').submit();
}
function initMap(latitude, longitude) {
var center = {lat: latitude, lng: longitude};
map = new google.maps.Map(document.getElementById('map'), {
zoom: 15,
center: center
});
var marker = new google.maps.Marker({
position: center,
map: map
});
infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.nearbySearch({
location: center,
radius: 1000,
type: ['restaurant']
}, callback);
var resultsSet = null;
$.ajax({
type : "GET",
url : "/history",
dataType : "json",
error : function(){
alert('통신실패!!');
},
success : function(data){
resultsSet = data;
}
});
function callback(results, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
createMarker(results[i], resultsSet);
}
}
}
function createMarker(place,resultsSet) {
var image1 = 'http://localhost:3000/images/restaurant_1.png'
var image2 = 'http://localhost:3000/images/restaurant_2.png'
var isMarked = false;
for (var i = 0; i < resultsSet.rows.length; i++) {
if(resultsSet.rows[i].contentid == place.id)
isMarked = true;
}
var placeLoc = place.geometry.location;
var marker1 = new google.maps.Marker({
map: map,
position: place.geometry.location,
icon: image1
});
var marker2 = new google.maps.Marker({
map: map,
position: place.geometry.location,
icon: image2
});
if(isMarked==true){
marker1.setMap(null);
}
else{
marker2.setMap(null);
}
var contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">'+place.name+'</h1>'+
'<div id="bodyContent">'+
'<p>주소: '+place.vicinity+'<br/>'+
'<button id="'+place.id+'" name="'+place.name+'" address="'+place.vicinity+'" onclick="addShop(this)">'+
'표시하기</a> '+
'</p>'+
'</div>'+
'</div>';
var contentString2 = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">'+place.name+'</h1>'+
'<div id="bodyContent">'+
'<p>주소: '+place.vicinity+'<br/>'+
'</p>'+
'</div>'+
'</div>';
google.maps.event.addListener(marker1, 'click', function(e) {
var infowindow = new google.maps.InfoWindow({
content: contentString,
maxWidth: 300
});
infowindow.open(map, this);
});
google.maps.event.addListener(marker2, 'click', function() {
var infowindow = new google.maps.InfoWindow({
content: contentString2,
maxWidth: 300
});
infowindow.open(map, this);
});
}
}
$(document).ready(function() {
// $('.sidenav').hide();
$('#show').click(function() {
//$('.sidenav').slideToggle("fast");
$this = $(this);
$nav = $('#mynav');
$nav.toggleClass('open');
});
$("input[name=first_name]");
if("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition(function(position) {
//console.log(position.coords.latitude)
//findShops(position.coords.latitude, position.coords.longitude);
initMap(position.coords.latitude, position.coords.longitude);
});
} else {
}
});
</script>
<div id ="show">clickmenu</div>
<div id ="maintitle">맛집견문록</div>
<div id ="mynav">
<ul class="sidenav">
<li><a class="active" href="home">home</a></li>
<li><a href="map">맛집도장찍기</a></li>
<li><a href="mybook">견문록확인</a></li>
</ul>
</div>
<div id = "title"> </div>
<div id ="content">
<div id="map"></div>
<div id="popup"></div>
<!-- <div id="form">
<form name="userform" method="POST" action="/map">
<input type="hidden" name="userid"/>
<input type="hidden" name="placeid"/>
<input type="hidden" name="placename"/>
<input type="hidden" name="placeaddress"/>
</form>
</div> -->
</div>
<div id ="footer"></div>
<form name="shop" method="post" action="/map">
<input type="hidden" name="useremail"/>
<input type="hidden" name="id"/>
<input type="hidden" name="title"/>
<input type="hidden" name="address"/>
</form>
</body>
</html>