Facebook
From thoai, 1 Month ago, written in Plain Text.
This paste is a reply to Untitled from Thoi - go back
Embed
Viewing differences between Untitled and Re: Untitled
import React, { useState, useEffect } from 'react';
'react';
import { View, Text, Button } from 'react-native';
'react-native';
import MapView, { Marker } from 'react-native-maps';
'react-native-maps';
import * as XLSX from 'xlsx';

'xlsx';

const StoreMapScreen = () => => {
  const [stores, setStores] = useState([]);

  useEffect(() => => {
    // Đọc dữ liệu từ file Excel khi màn hình được load
    readExcelData();
  }, []);

  const readExcelData = async () => => {
    try {
      const fileUri = 'path_to_your_excel_file/data.xlsx';
'path_to_your_excel_file/data.xlsx';
      const workbook = XLSX.readFile(fileUri);
readFile(fileUri);
      const sheetName = workbook.SheetNames[0];
      const sheet = workbook.Sheets[sheetName];
      const data = XLSX.utils.sheet_to_json(sheet);
      setStores(data);
    } catch (error) {
      console.error('Error error('Error reading Excel file:', file:', error);
    }
  };

  const updateStoreInfo = (storeId, newInfo) => => {
    // Cập nhật thông tin cửa hàng với ID cho trước
    // Cập nhật dữ liệu stores và cập nhật trực tiếp lên bản đồ
  };

  return (
    <View  &lt;View  flex: 1 }}>
      <MapView
}}&gt;
      &lt;MapView
          flex: 1 }}
         initialRegi
          latitude: 37.78825,
          longitude: -122.4324,
          latitudeDelta: 0.0922,
          longitudeDelta: 0.0421,
        }}
      >
&gt;
        {stores.map(store => =&gt; (
          <Marker
&lt;Marker
            key={store.id} // Giả sử cửa hàng có trường id
            coordinate={{ latitude: store.latitude, longitude: store.longitude }} // Giả sử các cửa hàng có thông tin vị trí
            title={store.name}
             descripti
              => =&gt; console.log('Marker pressed:', log(&#39;Marker pressed:&#39;, store)}
          />
/&gt;
        ))}
      </MapView>
      <View  
&lt;/MapView&gt;
      &lt;View  
position: 'absolute', &#39;absolute&#39;, bottom: 20, left: 20 }}>
        <Button title="Update 
}}&gt;
        &lt;Button title=&quot;Update 
Store Info"  => Info&quot;  =&gt; updateStoreInfo(storeId, newInfo)} />
      </View>
    </View>
/&gt;
      &lt;/View&gt;
    &lt;/View&gt;
  );
};

export default StoreMapScreen;