项目作者: QueenieCplusplus

项目描述 :
geo-location
高级语言: JavaScript
项目地址: git://github.com/QueenieCplusplus/React_geoApp.git
创建时间: 2020-07-20T10:20:13Z
项目社区:https://github.com/QueenieCplusplus/React_geoApp

开源协议:

下载


React_geoApp

geo-location

expo install

$ expo install expo-location

Codebase

  1. import React, { useState, useEffect } from 'react';
  2. import { Text, View } from 'react-native';
  3. import * as Location from 'expo-location';
  4. export default function App() {
  5. const [location, setLocation] = useState(null);
  6. const [errorMsg, setErrorMsg] = useState(null);
  7. useEffect(() => {
  8. (async () => {
  9. let { status } = await Location.requestPermissionsAsync();
  10. if (status !== 'granted') {
  11. setErrorMsg('Permission to access location was denied');
  12. }
  13. let location = await Location.getCurrentPositionAsync({});
  14. setLocation(location);
  15. })
  16. ();
  17. });
  18. let text = 'Waiting..';
  19. if (errorMsg) {
  20. text = errorMsg;
  21. } else if (location) {
  22. text = JSON.stringify(location);
  23. }
  24. return (
  25. <View>
  26. <Text>{text}</Text>
  27. </View>
  28. );
  29. }