Skip to content

Commit

Permalink
#2.7 Weather App - Location
Browse files Browse the repository at this point in the history
rn의 Dimensions api 사용 - 디바이스의 크기
Expo의 location api 사용 - 위치 사용 허용, 위치 가져오기, city가져오기
  • Loading branch information
rocher71 committed May 4, 2022
1 parent 06e584c commit 2fdff4d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
24 changes: 23 additions & 1 deletion NomadWeather/App.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
import { StatusBar } from "expo-status-bar";
import React from "react";
import * as Location from "expo-location";
import { View, Text, StyleSheet, ScrollView, Dimensions } from "react-native";
import { backgroundColor } from "react-native/Libraries/Components/View/ReactNativeStyleAttributes";
import { useEffect, useState } from "react";

const { width: SCREEN_WIDTH } = Dimensions.get("window");

export default function App() {
const [city, setCity] = useState("Loading...");
const [location, setLocation] = useState(null);
const [ok, setOk] = useState(true);
const ask = async () => {
const { granted } = await Location.requestForegroundPermissionsAsync();
if (!granted) {
setOk(false);
}
const {
coords: { latitude, longitude },
} = await Location.getCurrentPositionAsync({ accuracy: 5 });
const location = await Location.reverseGeocodeAsync(
{ latitude, longitude },
{ useGoogleMaps: false }
);
setCity(location[0].city);
};
useEffect(() => {
ask();
}, []);
return (
<View style={styles.container}>
<View style={styles.city}>
<Text style={styles.cityName}>Seoul</Text>
<Text style={styles.cityName}>{city}</Text>
</View>
<ScrollView
horizontal
Expand Down
36 changes: 36 additions & 0 deletions NomadWeather/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion NomadWeather/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"react": "17.0.1",
"react-dom": "17.0.1",
"react-native": "0.64.3",
"react-native-web": "0.17.1"
"react-native-web": "0.17.1",
"expo-location": "~14.0.1"
},
"devDependencies": {
"@babel/core": "^7.12.9"
Expand Down

0 comments on commit 2fdff4d

Please sign in to comment.