홍지윤

Update project directory

- google map 형식에 맞춰 삽입, 사용가능한지 확인.
- 주소 검색으로 마커,위도,경도 확인가능
- database 이용 직전까지.
...@@ -6,6 +6,8 @@ var postSchema = mongoose.Schema({ ...@@ -6,6 +6,8 @@ var postSchema = mongoose.Schema({
6 title:{type:String, required:[true, 'Title is required!']}, 6 title:{type:String, required:[true, 'Title is required!']},
7 body:{type:String, required:[true, 'Content is required!']}, 7 body:{type:String, required:[true, 'Content is required!']},
8 author:{type:mongoose.Schema.Types.ObjectId, ref:'user', required:true}, 8 author:{type:mongoose.Schema.Types.ObjectId, ref:'user', required:true},
9 + lat:{type:Number, required:true},
10 + lng:{type:Number, required:true},
9 createdAt:{type:Date, default:Date.now}, 11 createdAt:{type:Date, default:Date.now},
10 updatedAt:{type:Date}, 12 updatedAt:{type:Date},
11 }); 13 });
......
This diff is collapsed. Click to expand it.
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
17 "express": "^4.17.1", 17 "express": "^4.17.1",
18 "express-session": "^1.17.1", 18 "express-session": "^1.17.1",
19 "method-override": "^3.0.0", 19 "method-override": "^3.0.0",
20 - "mongoose": "^5.12.8", 20 + "mongoose": "^5.12.10",
21 "passport": "^0.4.1", 21 "passport": "^0.4.1",
22 "passport-local": "^1.0.0" 22 "passport-local": "^1.0.0"
23 } 23 }
......
1 +#map {
2 + height: 100%;
3 + }
4 +
5 + html,
6 + body {
7 + height: 100%;
8 + margin: 0;
9 + padding: 0;
10 + }
11 +
12 + #floating-panel {
13 + position: absolute;
14 + top: 10px;
15 + left: 25%;
16 + z-index: 5;
17 + background-color: #fff;
18 + padding: 5px;
19 + border: 1px solid #999;
20 + text-align: center;
21 + font-family: "Roboto", "sans-serif";
22 + line-height: 30px;
23 + padding-left: 10px;
24 + }
...\ No newline at end of file ...\ No newline at end of file
1 +<!--css-->
2 +<link rel="stylesheet" href="/css/map.css">
3 +
4 +<script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
5 +
6 +<!--google map geocode api key-->
7 +<script
8 + src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDK6K4iDdo9cKQdrNoOJaaYg29nEG0BIjw&callback=initMap&libraries=&v=weekly"
9 + async
10 +
11 +
12 +></script>
13 +
14 + <!--지도 띄우기 : 서울-->
15 +<script>
16 + function initMap() {
17 + const map = new google.maps.Map(document.getElementById("map"), {
18 + zoom: 8,
19 + center: { lat: 37.33, lng: 126.58 },
20 + });
21 +
22 + const geocoder = new google.maps.Geocoder();
23 + document.getElementById("submit").addEventListener("click", () => {
24 + geocodeAddress(geocoder, map);
25 + });
26 + }
27 + // geocodeAddress는 주소를 처리하고, marker를 생성하는 함수이다.
28 + function geocodeAddress(geocoder, resultsMap) {
29 + const address = document.getElementById('address').value;
30 + geocoder.geocode({ address: address }, (results, status) => {
31 + if (status === "OK") {
32 + var address_lat = results[0].geometry.location.lat();
33 + var address_lng = results[0].geometry.location.lng();
34 +
35 + resultsMap.setCenter(results[0].geometry.location);
36 + new google.maps.Marker({
37 + map: resultsMap,
38 + position: results[0].geometry.location,
39 + draggable : false
40 + });
41 + alert('주소 : '+address_lat+' '+address_lng);
42 + //alert위치에 mongoose에 주소를 저장하는 코드를 넣자!
43 + //show.ejs나 edit.ejs를 띄웠을 때 지도 위에 마커가 떠 있도록 하자.(기존 코드 변경)
44 + } else {
45 + alert(
46 + "Geocode was not successful for the following reason: " + status
47 + );
48 + }
49 + });
50 +
51 +
52 +}
53 +</script>
54 +
55 +<!--
56 +// views/posts에 new.ejs, edit.ejs 수정. show.ejs 수정.
57 +// views/partials에 map.ejs추가
58 +
59 +// routes/posts.js에 기능 추가
60 +// new, edit, show ejs 파일들에 지도 넣고, 마커 남기기 기능 완료.
61 +// marker의 주소를 저장하여(database), show ejs, edit.ejs시에 마커를 띄워주기.
62 +edit : 마커 남아있음, create mapmory button도 남아있음.
63 +show : 마커만 남아있음.
64 +-->
...@@ -49,5 +49,13 @@ ...@@ -49,5 +49,13 @@
49 </form> 49 </form>
50 50
51 </div> 51 </div>
52 + <!--map추가 code 시작.-->
53 + <%- include('../partials/map') %>
54 + <div id="map"></div>
55 + <div id="floating-panel">
56 + <input id="address" type="textbox" value="Seoul, Korea" />
57 + <input id="submit" type="button" value="Create Mapmory" />
58 + </div>
59 + <!--map추가 code끝-->
52 </body> 60 </body>
53 </html> 61 </html>
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -39,12 +39,20 @@ ...@@ -39,12 +39,20 @@
39 </div> 39 </div>
40 <% } %> 40 <% } %>
41 41
42 +
42 <div> 43 <div>
43 <a class="btn btn-primary" href="/posts">Back</a> 44 <a class="btn btn-primary" href="/posts">Back</a>
44 <button type="submit" class="btn btn-primary">Submit</button> 45 <button type="submit" class="btn btn-primary">Submit</button>
45 </div> 46 </div>
46 -
47 - </form>
48 </div> 47 </div>
48 + <!--map추가 code 시작.-->
49 + <%- include('../partials/map') %>
50 + <div id="map"></div>
51 + <div id="floating-panel">
52 + <input id="address" type="textbox" value="Seoul, Korea" />
53 + <input id="submit" type="button" value="Create Mapmory" />
54 + </div>
55 + <!--map추가 code끝-->
56 + </form>
49 </body> 57 </body>
50 </html> 58 </html>
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -50,5 +50,9 @@ ...@@ -50,5 +50,9 @@
50 </div> 50 </div>
51 51
52 </div> 52 </div>
53 + <!--map추가 code 시작.-->
54 + <%- include('../partials/map') %>
55 + <div id="map"></div>
56 + <!--map추가 code끝-->
53 </body> 57 </body>
54 </html> 58 </html>
...\ No newline at end of file ...\ No newline at end of file
......