노강호

위치기반 지도 띄우기 완료

...@@ -1203,6 +1203,29 @@ ...@@ -1203,6 +1203,29 @@
1203 "resolved": "https://registry.npmjs.org/@csstools/normalize.css/-/normalize.css-10.1.0.tgz", 1203 "resolved": "https://registry.npmjs.org/@csstools/normalize.css/-/normalize.css-10.1.0.tgz",
1204 "integrity": "sha512-ij4wRiunFfaJxjB0BdrYHIH8FxBJpOwNPhhAcunlmPdXudL1WQV1qoP9un6JsEBAgQH+7UXyyjh0g7jTxXK6tg==" 1204 "integrity": "sha512-ij4wRiunFfaJxjB0BdrYHIH8FxBJpOwNPhhAcunlmPdXudL1WQV1qoP9un6JsEBAgQH+7UXyyjh0g7jTxXK6tg=="
1205 }, 1205 },
1206 + "@emotion/is-prop-valid": {
1207 + "version": "0.8.8",
1208 + "resolved": "https://registry.npmjs.org/@emotion/is-prop-valid/-/is-prop-valid-0.8.8.tgz",
1209 + "integrity": "sha512-u5WtneEAr5IDG2Wv65yhunPSMLIpuKsbuOktRojfrEiEvRyC85LgPMZI63cr7NUqT8ZIGdSVg8ZKGxIug4lXcA==",
1210 + "requires": {
1211 + "@emotion/memoize": "0.7.4"
1212 + }
1213 + },
1214 + "@emotion/memoize": {
1215 + "version": "0.7.4",
1216 + "resolved": "https://registry.npmjs.org/@emotion/memoize/-/memoize-0.7.4.tgz",
1217 + "integrity": "sha512-Ja/Vfqe3HpuzRsG1oBtWTHk2PGZ7GR+2Vz5iYGelAw8dx32K0y7PjVuxK6z1nMpZOqAFsRUPCkK1YjJ56qJlgw=="
1218 + },
1219 + "@emotion/stylis": {
1220 + "version": "0.8.5",
1221 + "resolved": "https://registry.npmjs.org/@emotion/stylis/-/stylis-0.8.5.tgz",
1222 + "integrity": "sha512-h6KtPihKFn3T9fuIrwvXXUOwlx3rfUvfZIcP5a6rh8Y7zjE3O06hT5Ss4S/YI1AYhuZ1kjaE/5EaOOI2NqSylQ=="
1223 + },
1224 + "@emotion/unitless": {
1225 + "version": "0.7.5",
1226 + "resolved": "https://registry.npmjs.org/@emotion/unitless/-/unitless-0.7.5.tgz",
1227 + "integrity": "sha512-OWORNpfjMsSSUBVrRBVGECkhWcULOAJz9ZW8uK9qgxD+87M7jHRcvh/A96XXNhXTLmKcoYSQtBEX7lHMO7YRwg=="
1228 + },
1206 "@eslint/eslintrc": { 1229 "@eslint/eslintrc": {
1207 "version": "0.4.1", 1230 "version": "0.4.1",
1208 "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.4.1.tgz", 1231 "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.4.1.tgz",
...@@ -3273,6 +3296,22 @@ ...@@ -3273,6 +3296,22 @@
3273 "@babel/helper-define-polyfill-provider": "^0.2.1" 3296 "@babel/helper-define-polyfill-provider": "^0.2.1"
3274 } 3297 }
3275 }, 3298 },
3299 + "babel-plugin-styled-components": {
3300 + "version": "1.12.0",
3301 + "resolved": "https://registry.npmjs.org/babel-plugin-styled-components/-/babel-plugin-styled-components-1.12.0.tgz",
3302 + "integrity": "sha512-FEiD7l5ZABdJPpLssKXjBUJMYqzbcNzBowfXDCdJhOpbhWiewapUaY+LZGT8R4Jg2TwOjGjG4RKeyrO5p9sBkA==",
3303 + "requires": {
3304 + "@babel/helper-annotate-as-pure": "^7.0.0",
3305 + "@babel/helper-module-imports": "^7.0.0",
3306 + "babel-plugin-syntax-jsx": "^6.18.0",
3307 + "lodash": "^4.17.11"
3308 + }
3309 + },
3310 + "babel-plugin-syntax-jsx": {
3311 + "version": "6.18.0",
3312 + "resolved": "https://registry.npmjs.org/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz",
3313 + "integrity": "sha1-CvMqmm4Tyno/1QaeYtew9Y0NiUY="
3314 + },
3276 "babel-plugin-syntax-object-rest-spread": { 3315 "babel-plugin-syntax-object-rest-spread": {
3277 "version": "6.13.0", 3316 "version": "6.13.0",
3278 "resolved": "https://registry.npmjs.org/babel-plugin-syntax-object-rest-spread/-/babel-plugin-syntax-object-rest-spread-6.13.0.tgz", 3317 "resolved": "https://registry.npmjs.org/babel-plugin-syntax-object-rest-spread/-/babel-plugin-syntax-object-rest-spread-6.13.0.tgz",
...@@ -3933,6 +3972,11 @@ ...@@ -3933,6 +3972,11 @@
3933 "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.2.0.tgz", 3972 "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.2.0.tgz",
3934 "integrity": "sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg==" 3973 "integrity": "sha512-c7wVvbw3f37nuobQNtgsgG9POC9qMbNuMQmTCqZv23b6MIz0fcYpBiOlv9gEN/hdLdnZTDQhg6e9Dq5M1vKvfg=="
3935 }, 3974 },
3975 + "camelize": {
3976 + "version": "1.0.0",
3977 + "resolved": "https://registry.npmjs.org/camelize/-/camelize-1.0.0.tgz",
3978 + "integrity": "sha1-FkpUg+Yw+kMh5a8HAg5TGDGyYJs="
3979 + },
3936 "caniuse-api": { 3980 "caniuse-api": {
3937 "version": "3.0.0", 3981 "version": "3.0.0",
3938 "resolved": "https://registry.npmjs.org/caniuse-api/-/caniuse-api-3.0.0.tgz", 3982 "resolved": "https://registry.npmjs.org/caniuse-api/-/caniuse-api-3.0.0.tgz",
...@@ -4487,6 +4531,11 @@ ...@@ -4487,6 +4531,11 @@
4487 "postcss": "^7.0.5" 4531 "postcss": "^7.0.5"
4488 } 4532 }
4489 }, 4533 },
4534 + "css-color-keywords": {
4535 + "version": "1.0.0",
4536 + "resolved": "https://registry.npmjs.org/css-color-keywords/-/css-color-keywords-1.0.0.tgz",
4537 + "integrity": "sha1-/qJhbcZ2spYmhrOvjb2+GAskTgU="
4538 + },
4490 "css-color-names": { 4539 "css-color-names": {
4491 "version": "0.0.4", 4540 "version": "0.0.4",
4492 "resolved": "https://registry.npmjs.org/css-color-names/-/css-color-names-0.0.4.tgz", 4541 "resolved": "https://registry.npmjs.org/css-color-names/-/css-color-names-0.0.4.tgz",
...@@ -4570,6 +4619,16 @@ ...@@ -4570,6 +4619,16 @@
4570 "resolved": "https://registry.npmjs.org/css-select-base-adapter/-/css-select-base-adapter-0.1.1.tgz", 4619 "resolved": "https://registry.npmjs.org/css-select-base-adapter/-/css-select-base-adapter-0.1.1.tgz",
4571 "integrity": "sha512-jQVeeRG70QI08vSTwf1jHxp74JoZsr2XSgETae8/xC8ovSnL2WF87GTLO86Sbwdt2lK4Umg4HnnwMO4YF3Ce7w==" 4620 "integrity": "sha512-jQVeeRG70QI08vSTwf1jHxp74JoZsr2XSgETae8/xC8ovSnL2WF87GTLO86Sbwdt2lK4Umg4HnnwMO4YF3Ce7w=="
4572 }, 4621 },
4622 + "css-to-react-native": {
4623 + "version": "3.0.0",
4624 + "resolved": "https://registry.npmjs.org/css-to-react-native/-/css-to-react-native-3.0.0.tgz",
4625 + "integrity": "sha512-Ro1yETZA813eoyUp2GDBhG2j+YggidUmzO1/v9eYBKR2EHVEniE2MI/NqpTQ954BMpTPZFsGNPm46qFB9dpaPQ==",
4626 + "requires": {
4627 + "camelize": "^1.0.0",
4628 + "css-color-keywords": "^1.0.0",
4629 + "postcss-value-parser": "^4.0.2"
4630 + }
4631 + },
4573 "css-tree": { 4632 "css-tree": {
4574 "version": "1.0.0-alpha.37", 4633 "version": "1.0.0-alpha.37",
4575 "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-1.0.0-alpha.37.tgz", 4634 "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-1.0.0-alpha.37.tgz",
...@@ -13499,6 +13558,11 @@ ...@@ -13499,6 +13558,11 @@
13499 "safe-buffer": "^5.0.1" 13558 "safe-buffer": "^5.0.1"
13500 } 13559 }
13501 }, 13560 },
13561 + "shallowequal": {
13562 + "version": "1.1.0",
13563 + "resolved": "https://registry.npmjs.org/shallowequal/-/shallowequal-1.1.0.tgz",
13564 + "integrity": "sha512-y0m1JoUZSlPAjXVtPPW70aZWfIL/dSP7AFkRnniLCrK/8MDKog3TySTBmckD+RObVxH0v4Tox67+F14PdED2oQ=="
13565 + },
13502 "shebang-command": { 13566 "shebang-command": {
13503 "version": "1.2.0", 13567 "version": "1.2.0",
13504 "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz", 13568 "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-1.2.0.tgz",
...@@ -14160,6 +14224,23 @@ ...@@ -14160,6 +14224,23 @@
14160 "schema-utils": "^2.7.0" 14224 "schema-utils": "^2.7.0"
14161 } 14225 }
14162 }, 14226 },
14227 + "styled-components": {
14228 + "version": "5.3.0",
14229 + "resolved": "https://registry.npmjs.org/styled-components/-/styled-components-5.3.0.tgz",
14230 + "integrity": "sha512-bPJKwZCHjJPf/hwTJl6TbkSZg/3evha+XPEizrZUGb535jLImwDUdjTNxXqjjaASt2M4qO4AVfoHJNe3XB/tpQ==",
14231 + "requires": {
14232 + "@babel/helper-module-imports": "^7.0.0",
14233 + "@babel/traverse": "^7.4.5",
14234 + "@emotion/is-prop-valid": "^0.8.8",
14235 + "@emotion/stylis": "^0.8.4",
14236 + "@emotion/unitless": "^0.7.4",
14237 + "babel-plugin-styled-components": ">= 1.12.0",
14238 + "css-to-react-native": "^3.0.0",
14239 + "hoist-non-react-statics": "^3.0.0",
14240 + "shallowequal": "^1.1.0",
14241 + "supports-color": "^5.5.0"
14242 + }
14243 + },
14163 "stylehacks": { 14244 "stylehacks": {
14164 "version": "4.0.3", 14245 "version": "4.0.3",
14165 "resolved": "https://registry.npmjs.org/stylehacks/-/stylehacks-4.0.3.tgz", 14246 "resolved": "https://registry.npmjs.org/stylehacks/-/stylehacks-4.0.3.tgz",
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
12 "react-dom": "^17.0.2", 12 "react-dom": "^17.0.2",
13 "react-router-dom": "^5.2.0", 13 "react-router-dom": "^5.2.0",
14 "react-scripts": "4.0.3", 14 "react-scripts": "4.0.3",
15 + "styled-components": "^5.3.0",
15 "web-vitals": "^1.1.2" 16 "web-vitals": "^1.1.2"
16 }, 17 },
17 "scripts": { 18 "scripts": {
...@@ -37,4 +38,3 @@ ...@@ -37,4 +38,3 @@
37 ] 38 ]
38 } 39 }
39 } 40 }
40 -
......
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html lang="ko"> 2 <html lang="ko">
3 <head> 3 <head>
4 - <script
5 - type="text/javascript"
6 - src="//dapi.kakao.com/v2/maps/sdk.js?appkey=059ebad3d5ccd28178357c542b8c80d1&libraries=services"
7 - ></script>
8 <meta charset="utf-8" /> 4 <meta charset="utf-8" />
9 <link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> 5 <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
10 <meta name="viewport" content="width=device-width, initial-scale=1" /> 6 <meta name="viewport" content="width=device-width, initial-scale=1" />
...@@ -29,6 +25,8 @@ ...@@ -29,6 +25,8 @@
29 Learn how to configure a non-root public URL by running `npm run build`. 25 Learn how to configure a non-root public URL by running `npm run build`.
30 --> 26 -->
31 <title>Momokji</title> 27 <title>Momokji</title>
28 + <script src="https://dapi.kakao.com/v2/maps/sdk.js?appkey=059ebad3d5ccd28178357c542b8c80d1
29 +"></script>
32 </head> 30 </head>
33 <body> 31 <body>
34 <noscript>You need to enable JavaScript to run this app.</noscript> 32 <noscript>You need to enable JavaScript to run this app.</noscript>
......
1 /*global kakao*/ 1 /*global kakao*/
2 import React, { useEffect } from "react"; 2 import React, { useEffect } from "react";
3 3
4 -const Map = () => { 4 +const Location = () => {
5 useEffect(() => { 5 useEffect(() => {
6 - var mapContainer = document.getElementById("map"); 6 + var container = document.getElementById("map");
7 - var mapOption = { 7 + var options = {
8 center: new kakao.maps.LatLng(37.365264512305174, 127.10676860117488), 8 center: new kakao.maps.LatLng(37.365264512305174, 127.10676860117488),
9 level: 3, 9 level: 3,
10 }; 10 };
11 - 11 + var map = new kakao.maps.Map(container, options);
12 - var map = new kakao.maps.Map(mapContainer, mapOption);
13 - var markerPosition = new kakao.maps.LatLng(
14 - 37.365264512305174,
15 - 127.10676860117488
16 - );
17 - var marker = new kakao.maps.Marker({
18 - position: markerPosition,
19 - });
20 - marker.setMap(map);
21 }, []); 12 }, []);
22 13
23 - return ( 14 + return <div></div>;
24 - <div
25 - id="map"
26 - style="width: 100%; height: 100%; position: relative; overflow: hidden"
27 - ></div>
28 - );
29 }; 15 };
30 16
31 -export default Map; 17 +export default Location;
......
1 +/*global kakao*/
2 +import React, { Component, useCallback } from "react";
3 +import styled from "styled-components";
4 +
5 +const { kakao } = window;
6 +
7 +var nowlat, nowlon;
8 +
9 +class MapContainer extends Component {
10 + constructor(props) {
11 + super(props);
12 +
13 + this.state = {
14 + isLoading: true,
15 + lat: 37.506502,
16 + lon: 127.053617,
17 + };
18 +
19 + this.getLocation = this.getLocation.bind(this);
20 + this.getMap = this.getMap.bind(this);
21 + this.componentDidMount = this.componentDidMount.bind(this);
22 + }
23 +
24 + sleep = (ms) => {
25 + return new Promise((resolve) => setTimeout(resolve, ms));
26 + };
27 +
28 + getLocation = (callback) => {
29 + if (navigator.geolocation) {
30 + // GeoLocation을 이용해서 접속 위치를 얻어옵니다
31 + navigator.geolocation.getCurrentPosition(function (position) {
32 + nowlat = position.coords.latitude; // 위도
33 + nowlon = position.coords.longitude; // 경도
34 + console.log(nowlat, nowlon);
35 + var locPosition = new kakao.maps.LatLng(nowlat, nowlon); // 마커가 표시될 위치를 geolocation으로 얻어온 좌표로 생성합니다
36 + //message = '<div style="padding:5px;">여기에 계신가요?!</div>'; // 인포윈도우에 표시될 내용입니다
37 +
38 + // 마커와 인포윈도우를 표시합니다
39 + //displayMarker(locPosition, message);
40 + callback();
41 + //return locPosition;
42 + });
43 + } else {
44 + // HTML5의 GeoLocation을 사용할 수 없을때 마
45 + nowlat = 37.506502; // 위도
46 + nowlon = 127.053617; // 경도커 표시 위치와 인포윈도우 내용을 설정합니다
47 +
48 + var locPosition = new kakao.maps.LatLng(37.506502, 127.053617);
49 + //message = "geolocation을 사용할수 없어요..";
50 +
51 + //displayMarker(locPosition, message);
52 + callback();
53 + }
54 + };
55 +
56 + getMap = () => {
57 + this.getLocation(() => {
58 + this.setState({ lat: nowlat, lon: nowlon });
59 + let container = document.getElementById("Mymap");
60 + let options = {
61 + center: new kakao.maps.LatLng(this.state.lat, this.state.lon),
62 + level: 7,
63 + };
64 +
65 + const map = new window.kakao.maps.Map(container, options);
66 + });
67 + };
68 +
69 + componentDidMount() {
70 + this.getMap();
71 + }
72 +
73 + render() {
74 + return <MapContents id="Mymap"></MapContents>; // 이부분이 지도를 띄우게 부분.
75 + }
76 +}
77 +
78 +const MapContents = styled.div`
79 + width: 500px;
80 + height: 400px;
81 +`;
82 +
83 +export default MapContainer;
1 -import React, { useState } from "react";
2 -import MapContainer from "./Sections/MapContainer";
3 -
4 -function LandingPage() {
5 - const [InputText, setInputText] = useState("");
6 - const [Place, setPlace] = useState("");
7 -
8 - const onChange = (e) => {
9 - setInputText(e.target.value);
10 - };
11 -
12 - const handleSubmit = (e) => {
13 - e.preventDefault();
14 - setPlace(InputText);
15 - setInputText("");
16 - };
17 -
18 - return (
19 - <>
20 - <form className="inputForm" onSubmit={handleSubmit}>
21 - <input
22 - placeholder="검색어를 입력하세요"
23 - onChange={onChange}
24 - value={InputText}
25 - />
26 - <button type="submit">검색</button>
27 - </form>
28 - <MapContainer searchPlace={Place} />
29 - </>
30 - );
31 -}
32 -
33 -export default LandingPage;
1 -import React, { useEffect } from "react";
2 -
3 -const { kakao } = window;
4 -console.log(kakao);
5 -console.log(window);
6 -
7 -const MapContainer = ({ searchPlace }) => {
8 - useEffect(() => {
9 - var infowindow = new kakao.maps.InfoWindow({ zIndex: 1 });
10 - const container = document.getElementById("myMap");
11 - const options = {
12 - center: new kakao.maps.LatLng(33.450701, 126.570667),
13 - level: 3,
14 - };
15 - const map = new kakao.maps.Map(container, options);
16 -
17 - const ps = new kakao.maps.services.Places();
18 -
19 - ps.keywordSearch(searchPlace, placesSearchCB);
20 -
21 - function placesSearchCB(data, status, pagination) {
22 - if (status === kakao.maps.services.Status.OK) {
23 - let bounds = new kakao.maps.LatLngBounds();
24 -
25 - for (let i = 0; i < data.length; i++) {
26 - displayMarker(data[i]);
27 - bounds.extend(new kakao.maps.LatLng(data[i].y, data[i].x));
28 - }
29 -
30 - map.setBounds(bounds);
31 - }
32 - }
33 -
34 - function displayMarker(place) {
35 - let marker = new kakao.maps.Marker({
36 - map: map,
37 - position: new kakao.maps.LatLng(place.y, place.x),
38 - });
39 -
40 - // 마커에 클릭이벤트를 등록합니다
41 - kakao.maps.event.addListener(marker, "click", function () {
42 - // 마커를 클릭하면 장소명이 인포윈도우에 표출됩니다
43 - infowindow.setContent(
44 - '<div style="padding:5px;font-size:12px;">' +
45 - place.place_name +
46 - "</div>"
47 - );
48 - infowindow.open(map, marker);
49 - });
50 - }
51 - }, [searchPlace]);
52 -
53 - return (
54 - <div
55 - id="myMap"
56 - style={{
57 - width: "500px",
58 - height: "500px",
59 - }}
60 - ></div>
61 - );
62 -};
63 -
64 -export default MapContainer;
1 import React, { useEffect } from "react"; 1 import React, { useEffect } from "react";
2 -import MapContainer from "../components/views/Landing/Sections/MapContainer"; 2 +import MapContainer from "../components/MapContainer";
3 +import Map from "../components/Map";
3 4
4 const Home = () => { 5 const Home = () => {
5 return ( 6 return (
......