250x250
Rainbow๐ŸŒˆCoder
My dev Note๐Ÿ“’
Rainbow๐ŸŒˆCoder
์ „์ฒด ๋ฐฉ๋ฌธ์ž
์˜ค๋Š˜
์–ด์ œ
  • ๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ (411)
    • ๊ณต์ง€์‚ฌํ•ญ (0)
    • Debugger (10)
      • Visual Studio Debugger (1)
      • Chrome DevTools (3)
      • Visual Studio Code Debugger (4)
      • eclipse (1)
      • intelliJ (1)
    • OOP (2)
      • OOP (2)
    • TypeScript (54)
      • ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ TypeScript (54)
    • Javascript (87)
      • Javascript (45)
      • Node.js (19)
      • React (5)
      • FE ๊ฐœ๋ฐœํ™˜๊ฒฝ์„ค์ • (3)
      • React์™€ Node ๊ฐ™์ด ๋•Œ๋ ค์žก๊ธฐ (6)
      • next.js (2)
      • pixi.js (7)
    • ๋งˆํฌ์—… (23)
      • Html & Css (23)
    • C# (80)
      • C# (12)
      • ์ด๊ฒƒ์ด C#์ด๋‹ค (68)
    • C++ (30)
      • c++ (27)
      • win api (3)
    • Unity (18)
      • Unity(๊ธฐ์ดˆ) (8)
      • Unity(C#์ค‘๊ธ‰) (5)
      • ์œ ๋‹ˆํ‹ฐ ํฌํ†ค(๋„คํŠธ์›Œํฌ) (4)
      • unity c# MyCode (1)
    • Java & Spring (29)
      • Java (11)
      • ์Šคํ”„๋ง (8)
      • Java Algorithm (9)
      • Javs Data Structures (1)
    • ์ž๋ฃŒ๊ตฌ์กฐ์™€ ์•Œ๊ณ ๋ฆฌ์ฆ˜ (15)
      • ์ž๋ฃŒ๊ตฌ์กฐ (5)
      • ์•Œ๊ณ ๋ฆฌ์ฆ˜ (10)
    • ํ˜•์ƒ๊ด€๋ฆฌ (15)
      • Git (11)
      • ์†Œ์ŠคํŠธ๋ฆฌ (3)
    • ๊ทธ๋ž˜ํ”ฝ์Šค (7)
      • WebGl (7)
    • AWS (3)
      • aws (3)
    • ๋ฆฌ๋ˆ…์Šค (5)
      • ๋ฆฌ๋ˆ…์Šค (5)
    • ์ฑ… ๋ฆฌ๋ทฐ (13)
      • ํด๋ฆฐ์ฝ”๋“œ(์ฑ…๋ฆฌ๋ทฐ) (3)
      • ์œ ์ง€๋ณด์ˆ˜๊ฐ€๋Šฅํ•œ์ฝ”๋”ฉ์˜๊ธฐ์ˆ C#ํŽธ(์ฑ…๋ฆฌ๋ทฐ) (1)
      • ๋ฆฌํŒฉํ† ๋ง(์ž๋ฐ”์Šคํฌ๋ฆฝํŠธํŒ) (9)
    • Server (2)
      • ๊ฒŒ์ž„ ์„œ๋ฒ„(๋„คํŠธ์›Œํฌ, ๋ฉ€ํ‹ฐ์“ฐ๋ ˆ๋“œ,OS) (2)
    • ์„ค๊ณ„, ์•„ํ‚คํ…์ณ (4)
    • ํŒŒ์ด์ฌ (5)
    • ๋””์ž์ธํŒจํ„ด (2)
    • mocha (2)
    • Jest (1)
    • Spine (1)
    • ์ธ๊ณต์ง€๋Šฅ (1)
      • ํ˜ผ์ž๊ณต๋ถ€ํ•˜๋Š”๋จธ์‹ ๋Ÿฌ๋‹+๋”ฅ๋Ÿฌ๋‹ (1)

๋ธ”๋กœ๊ทธ ๋ฉ”๋‰ด

  • ํ™ˆ
  • ํƒœ๊ทธ
  • ๋ฐฉ๋ช…๋ก

๊ณต์ง€์‚ฌํ•ญ

์ธ๊ธฐ ๊ธ€

ํƒœ๊ทธ

  • MySQL
  • ใ…ฃใ„ท
  • ์ปดํฌ์ง€์…˜
  • ์œ„์ž„

์ตœ๊ทผ ๋Œ“๊ธ€

์ตœ๊ทผ ๊ธ€

ํ‹ฐ์Šคํ† ๋ฆฌ

hELLO ยท Designed By ์ •์ƒ์šฐ.
Rainbow๐ŸŒˆCoder

My dev Note๐Ÿ“’

[React + Node ๊ฐ™์ด ๋•Œ๋ ค์žก๊ธฐ] (4) ์œ„์น˜ ๋„์‹œ ๊ธฐ๋ฐ˜ ๋‚ ์”จ ์•ฑ (api ์—ฐ๊ฒฐ ๊ธฐ์ดˆ์ž‘์—…, UI์ž‘์—… )
Javascript/React์™€ Node ๊ฐ™์ด ๋•Œ๋ ค์žก๊ธฐ

[React + Node ๊ฐ™์ด ๋•Œ๋ ค์žก๊ธฐ] (4) ์œ„์น˜ ๋„์‹œ ๊ธฐ๋ฐ˜ ๋‚ ์”จ ์•ฑ (api ์—ฐ๊ฒฐ ๊ธฐ์ดˆ์ž‘์—…, UI์ž‘์—… )

2022. 12. 7. 16:36
728x90

1. ๊ธฐ๋Šฅ ๋ช…์„ธ์„œ

//1. ์•ฑ์ด ์‹คํ–‰๋˜์ž๋งˆ์ž ํ˜„์žฌ ์œ„์น˜ ๊ธฐ๋ฐ˜์˜ ๋‚ ์”จ๊ฐ€ ๋ณด์ธ๋‹ค.
//2. ๋‚ ์”จ ์ •๋ณด์—๋Š” ๋„์‹œ, ์„ญ์”จ, ํ™”์”จ ๋‚ ์”จ ์ƒํƒœ
//3. 5๊ฐœ์˜ ๋ฒ„ํŠผ์ด ์žˆ๋‹ค (1๊ฐœ๋Š” ํ˜„์žฌ ์œ„์น˜, 4๊ฐœ๋Š” ๋‹ค๋ฅธ ๋„์‹œ)
//4. ๋กœ๋”ฉ ์Šคํ”ผ๋„ˆ ๊ธฐ๋Šฅ ์ถ”๊ฐ€

 

2. weather api

https://openweathermap.org/api

 

Weather API - OpenWeatherMap

Please, sign up to use our fast and easy-to-work weather APIs. As a start to use OpenWeather products, we recommend our One Call API 3.0. For more functionality, please consider our products, which are included in professional collections.

openweathermap.org

๋งํฌ์—์„œ ํšŒ์›๊ฐ€์ž…ํ•˜๊ณ  ์ œ๊ณต๋ฐ›์€ key๋ฅผ ์ด์šฉํ•˜๊ณ 

๋ฌด๋ฃŒ api๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์œ„์น˜, ๋„์‹œ ๊ธฐ๋ฐ˜ ๋‚ ์”จ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์™€๋ณด๋„๋ก ํ•œ๋‹ค.

 

9007b03099d0209ad491e058a2d63c26

 

3. Using HTML Geolocation

https://www.w3schools.com/html/html5_geolocation.asp

 

HTML Geolocation API

W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

www.w3schools.com

ํ•ด๋‹น ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ํ˜„์žฌ ์œ„์น˜๋ฅผ ๋ณด์—ฌ์ฃผ๋Š” ์ฝ”๋“œ๋ฅผ App.js์— ์ž‘์„ฑํ•œ๋‹ค.

import './App.css';
import { useEffect, useState } from 'react';

//1. ์•ฑ์ด ์‹คํ–‰๋˜์ž๋งˆ์ž ํ˜„์žฌ ์œ„์น˜ ๊ธฐ๋ฐ˜์˜ ๋‚ ์”จ๊ฐ€ ๋ณด์ธ๋‹ค.
//2. ๋‚ ์”จ ์ •๋ณด์—๋Š” ๋„์‹œ, ์„ญ์”จ, ํ™”์”จ ๋‚ ์”จ ์ƒํƒœ
//3. 5๊ฐœ์˜ ๋ฒ„ํŠผ์ด ์žˆ๋‹ค (1๊ฐœ๋Š” ํ˜„์žฌ ์œ„์น˜, 4๊ฐœ๋Š” ๋‹ค๋ฅธ ๋„์‹œ)
//4. ๋กœ๋”ฉ ์Šคํ”ผ๋„ˆ ๊ธฐ๋Šฅ ์ถ”๊ฐ€

function App() {
	const getCurrentLocation = () => {
		if (navigator.geolocation) {
			navigator.geolocation.getCurrentPosition((position) => {
				const latitude = position.coords.latitude;
				const longitude = position.coords.longitude;
				alert('ํ˜„์žฌ ์œ„์น˜๋Š” ' + latitude + ' ' + longitude);
			});
		} else {
			alert("Geolocation is not supported by this browser.");
		}
	}

	useEffect(() => {
		getCurrentLocation()
	}, []);
	return (
		<div>
			๋„ˆ์˜ ๋‚ ์”จ๋Š”
		</div>
	);
}

export default App;

 

4. api๋ฅผ ํ˜ธ์ถœํ•ด์„œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์™€ ์„ธํŒ…ํ•˜๊ธฐ

 

import './App.css';
import { useEffect, useState } from 'react';

//1. ์•ฑ์ด ์‹คํ–‰๋˜์ž๋งˆ์ž ํ˜„์žฌ ์œ„์น˜ ๊ธฐ๋ฐ˜์˜ ๋‚ ์”จ๊ฐ€ ๋ณด์ธ๋‹ค.
//2. ๋‚ ์”จ ์ •๋ณด์—๋Š” ๋„์‹œ, ์„ญ์”จ, ํ™”์”จ ๋‚ ์”จ ์ƒํƒœ
//3. 5๊ฐœ์˜ ๋ฒ„ํŠผ์ด ์žˆ๋‹ค (1๊ฐœ๋Š” ํ˜„์žฌ ์œ„์น˜, 4๊ฐœ๋Š” ๋‹ค๋ฅธ ๋„์‹œ)
//4. ๋กœ๋”ฉ ์Šคํ”ผ๋„ˆ ๊ธฐ๋Šฅ ์ถ”๊ฐ€

const choice = {
	Seoul: { name: 'Seoul' },
	NewYork: { name: 'NewYork' },
	Toronto: { name: 'Toronto' },
	Paris: { name: 'Paris' },
	Rondon: { name: 'Rondon' }
}

function App() {
	const [userLocation, setUserLocation] = useState(null);
	const clickCity = (userChoice) => {
		setUserLocation(choice[userChoice]);
	}
	const getCurrentLocation = () => {
		if (navigator.geolocation) {
			navigator.geolocation.getCurrentPosition((position) => {
				const latitude = position.coords.latitude;
				const longitude = position.coords.longitude;
				getWeatherByCurrentLocation(latitude, longitude);
			});
		} else {
			alert("Geolocation is not supported by this browser.");
		}
	}

	//await ์“ฐ๊ณ ์ž ํ•˜๋Š” ํ•จ์ˆ˜๋Š” async ์—ฌ์•ผ ํ•œ๋‹ค! 
	const getWeatherByCurrentLocation = async (lat, lon) => {
		let url = `https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=9007b03099d0209ad491e058a2d63c26`;
		let response = await fetch(url) //๋น„๋™๊ธฐ(์ง๋…: url์„ patchํ•˜๋Š” ๊ฒƒ์„ ๊ธฐ๋‹ค๋ ค๋‹ฌ๋ผ!) : url ๋กœ๋”ฉํ•œ ๋’ค ์‘๋‹ต๊ฐ’์„ ๋ฐ›๊ธฐ๋กœ ํ•จ
		let data = await response.json(); //์‘๋‹ต์—์„œ json ์ถ”์ถœํ•˜๋Š” ๊ฒƒ์„ ๊ธฐ๋‹ค๋ ค๋‹ฌ๋ผ
	}

	useEffect(() => {
		getCurrentLocation()
	}, []);
	
	return (
		<div>
			<div>
				<button onClick={() => clickCity('Seoul')}>Seoul</button>
			</div>

			<div>
			</div>
		</div>
	);
}

export default App;

 

 

5. ๊ธฐ๋ณธ UI ์ž‘์—…

 

https://react-bootstrap.github.io/

 

React-Bootstrap

The most popular front-end framework, rebuilt for React.

react-bootstrap.github.io

์„œ๋ฒ„ ์ข…๋ฃŒ ํ›„ ์„ค์น˜ 

npm install react-bootstrap bootstrap

๊ธฐ๋ณธ์ ์ธ ๋ถ€ํŠธ์ŠคํŠธ๋žฉ ๊นŒ์ง€ ์ฒ˜๋ฆฌํ•ด์ฃผ๊ณ  ๋ Œ๋”๋ง๋œ ํด๋ผ ํ™”๋ฉด

์ง€๊ธˆ๊นŒ์ง€์˜ ์†Œ์Šค ์ŠคํŽ™

 

App.js

import './App.css';
import { useEffect, useState } from 'react';
import WeatherBox from "./component/WaetherBox";
import WeatherButton from "./component/WeatherButton";
import 'bootstrap/dist/css/bootstrap.min.css';

//1. ์•ฑ์ด ์‹คํ–‰๋˜์ž๋งˆ์ž ํ˜„์žฌ ์œ„์น˜ ๊ธฐ๋ฐ˜์˜ ๋‚ ์”จ๊ฐ€ ๋ณด์ธ๋‹ค.
//2. ๋‚ ์”จ ์ •๋ณด์—๋Š” ๋„์‹œ, ์„ญ์”จ, ํ™”์”จ ๋‚ ์”จ ์ƒํƒœ
//3. 5๊ฐœ์˜ ๋ฒ„ํŠผ์ด ์žˆ๋‹ค (1๊ฐœ๋Š” ํ˜„์žฌ ์œ„์น˜, 4๊ฐœ๋Š” ๋‹ค๋ฅธ ๋„์‹œ)
//4. ๋กœ๋”ฉ ์Šคํ”ผ๋„ˆ ๊ธฐ๋Šฅ ์ถ”๊ฐ€

const choice = {
	Seoul: { name: 'Seoul' },
	NewYork: { name: 'NewYork' },
	Toronto: { name: 'Toronto' },
	Paris: { name: 'Paris' },
	Rondon: { name: 'Rondon' }
}

function App() {
	const [userLocation, setUserLocation] = useState(null);
	const clickCity = (userChoice) => {
		setUserLocation(choice[userChoice]);
	}
	const getCurrentLocation = () => {
		if (navigator.geolocation) {
			navigator.geolocation.getCurrentPosition((position) => {
				const latitude = position.coords.latitude;
				const longitude = position.coords.longitude;
				getWeatherByCurrentLocation(latitude, longitude);
			});
		} else {
			alert("Geolocation is not supported by this browser.");
		}
	}

	//await ์“ฐ๊ณ ์ž ํ•˜๋Š” ํ•จ์ˆ˜๋Š” async ์—ฌ์•ผ ํ•œ๋‹ค! 
	const getWeatherByCurrentLocation = async (lat, lon) => {
		let url = `https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=9007b03099d0209ad491e058a2d63c26`;
		let response = await fetch(url) //๋น„๋™๊ธฐ(์ง๋…: url์„ patchํ•˜๋Š” ๊ฒƒ์„ ๊ธฐ๋‹ค๋ ค๋‹ฌ๋ผ!) : url ๋กœ๋”ฉํ•œ ๋’ค ์‘๋‹ต๊ฐ’์„ ๋ฐ›๊ธฐ๋กœ ํ•จ
		let data = await response.json(); //์‘๋‹ต์—์„œ json ์ถ”์ถœํ•˜๋Š” ๊ฒƒ์„ ๊ธฐ๋‹ค๋ ค๋‹ฌ๋ผ
	}

	useEffect(() => {
		getCurrentLocation()
	}, []);

	return (
		<div>
			<div>
				<WeatherBox />
				<WeatherButton title="Seoul" />
				<WeatherButton title="NewYork" />
				<WeatherButton title="Toronto" />
				<WeatherButton title="Paris" />
				<WeatherButton title="Rondon" />
			</div>
			<div>
			</div>
		</div>
	);
}

export default App;

 

App.css

body{
	background : url(https://wallpaperaccess.com/full/5466320.jpg);
	height: 100vh;
	background-repeat: no-repeat;
	background-size: cover;
}

.weather-box{
	color : #aec6fe;
}

WeatherButton.js

import React from 'react'
import { Button } from 'react-bootstrap';

const WeatherButton = (props) => {
	return (
		<div>
			<Button variant="primary">{props.title}</Button>
		</div>
	)
}

export default WeatherButton

 

WeatherBox.js

import React from 'react'

const WaetherBox = () => {
	return (
		<div className='weather-box'>
			<div>Your Weather</div>
			<h2>30๋„ / 230 ํ™”์”จ</h2>
			<h2>๋ง‘์€ ํ•˜๋Š˜</h2>
		</div>
	)
}

export default WaetherBox

๊ธฐํƒ€ ๋ฐ˜์‘ํ˜• ์›น์œผ๋กœ ๋งˆํฌ์—… ํ•˜๋Š” ๊ณผ์ •์€ ํ•ด๋‹น ํฌ์ŠคํŒ…(ํด๋ฆญ)์— ๋‹ด์•˜๋‹ค.

728x90

'Javascript > React์™€ Node ๊ฐ™์ด ๋•Œ๋ ค์žก๊ธฐ' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[React + Node ๊ฐ™์ด ๋•Œ๋ ค์žก๊ธฐ] (6) npm ๋ฆฌ์•กํŠธ ๋กœ๋”ฉ์Šคํ”ผ๋„ˆ + ์œ„์น˜ ๋„์‹œ ๊ธฐ๋ฐ˜ ๋‚ ์”จ ์•ฑ ์™„์„ฑ  (0) 2022.12.10
[React + Node ๊ฐ™์ด ๋•Œ๋ ค์žก๊ธฐ] (5) react one-way data flow + ์œ„์น˜ ๋„์‹œ ๊ธฐ๋ฐ˜ ๋‚ ์”จ ์•ฑ ๊ณ„์† making  (0) 2022.12.09
[React + Node ๊ฐ™์ด ๋•Œ๋ ค์žก๊ธฐ] (3) ๋ฆฌ์•กํŠธ ํด๋ž˜์Šค ์ปดํฌ๋„ŒํŠธ, ๋ผ์ดํ”„ ์‚ฌ์ดํด  (0) 2022.12.05
[React + Node ๊ฐ™์ด ๋•Œ๋ ค์žก๊ธฐ] (2) ๋ฆฌ์•กํŠธ ๊ฐ€์œ„๋ฐ”์œ„๋ณด ๊ฒŒ์ž„  (0) 2022.12.04
[React + Node ๊ฐ™์ด ๋•Œ๋ ค์žก๊ธฐ] (1) ๋ฆฌ์•กํŠธ์˜ ์ปจ์…‰ state  (0) 2022.12.02
    'Javascript/React์™€ Node ๊ฐ™์ด ๋•Œ๋ ค์žก๊ธฐ' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€
    • [React + Node ๊ฐ™์ด ๋•Œ๋ ค์žก๊ธฐ] (6) npm ๋ฆฌ์•กํŠธ ๋กœ๋”ฉ์Šคํ”ผ๋„ˆ + ์œ„์น˜ ๋„์‹œ ๊ธฐ๋ฐ˜ ๋‚ ์”จ ์•ฑ ์™„์„ฑ
    • [React + Node ๊ฐ™์ด ๋•Œ๋ ค์žก๊ธฐ] (5) react one-way data flow + ์œ„์น˜ ๋„์‹œ ๊ธฐ๋ฐ˜ ๋‚ ์”จ ์•ฑ ๊ณ„์† making
    • [React + Node ๊ฐ™์ด ๋•Œ๋ ค์žก๊ธฐ] (3) ๋ฆฌ์•กํŠธ ํด๋ž˜์Šค ์ปดํฌ๋„ŒํŠธ, ๋ผ์ดํ”„ ์‚ฌ์ดํด
    • [React + Node ๊ฐ™์ด ๋•Œ๋ ค์žก๊ธฐ] (2) ๋ฆฌ์•กํŠธ ๊ฐ€์œ„๋ฐ”์œ„๋ณด ๊ฒŒ์ž„
    Rainbow๐ŸŒˆCoder
    Rainbow๐ŸŒˆCoder
    ๋ชฐ๋ผ๋„ ๊ฒฐ๊ตญ์€ ์•„๋Š” ๊ฐœ๋ฐœ์ž, ๊ทธ๋Ÿฐ ์‚ฌ๋žŒ์ด ๋˜๊ธฐ ์œ„ํ•œ ๋งค์ผ์˜ ํ•œ๊ฑธ์Œ

    ํ‹ฐ์Šคํ† ๋ฆฌํˆด๋ฐ”