import React, { useEffect, useState } from "react"; import { Text, StyleSheet, View, PermissionsAndroid } from "react-native"; import MapView, { Marker } from "react-native-maps"; import * as Location from "expo-location"; import { LocationObject } from "expo-location"; import { mapStyle } from "../../style/map"; export default function Index() { /**********************************狀態管理**********************************/ const [location, setLocation] = useState(); useEffect(() => { (async () => { let { status } = await Location.requestForegroundPermissionsAsync(); if (status !== "granted") { console.log("Permission denied"); return; } let location = await Location.getCurrentPositionAsync({}); setLocation(location); })(); }, []); /**********************************狀態管理**********************************/ /**********************************組件初始化**********************************/ /**********************************組件初始化**********************************/ /**********************************異步函數**********************************/ /**********************************異步函數**********************************/ return ( {location && ( {}} description="Marker Description" /> )} ); } const styles = StyleSheet.create({ container: { flex: 1, }, map: { width: "100%", height: "100%", }, });