import React, {useEffect, useState} from 'react'; import {View, StyleSheet, Alert} from 'react-native'; import MapView, {Marker, PROVIDER_GOOGLE} from 'react-native-maps'; import {url} from '../url'; import {RED} from '../color'; export default function Map({ lat, long, showsUserLocation, latDelta, longDelta, children, }) { const [potholeLocation, setPotholeLocation] = useState(); const sendPostRequest = async () => { try { const timestamp = Math.floor(Date.now() / 1000); // 타임스탬프를 생성하거나 필요한 값으로 대체 const response = await fetch(`${url}/action/pothole_display`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ timestamp: timestamp, }), }); if (response.ok) { const data = await response.json(); setPotholeLocation( data.pothole.map(item => { return { latitude: item[0], longitude: item[1], }; }), ); } else { console.error('Server returned an error.', error); } } catch (error) { console.error('An error occurred:', error); } }; // 화면이 처음 렌더링될 때 sendPostRequest 호출 useEffect(() => { sendPostRequest(); Alert.alert('알림', 'bump 발생'); }, []); // 두 번째 매개변수로 빈 배열을 전달하여 화면이 처음 렌더링될 때 한 번만 실행 return ( {children} {potholeLocation && potholeLocation.length > 0 && potholeLocation.map((location, index) => ( ))} ); } const styles = StyleSheet.create({ mapStyle: { flex: 1, }, });