Facebook
From Thoi, 1 Month ago, written in JavaScript.
Embed
Download Paste or View Raw
Hits: 124
  1. import React, { useState, useEffect } from 'react';
  2. import { View, Text, Button } from 'react-native';
  3. import MapView, { Marker } from 'react-native-maps';
  4. import * as XLSX from 'xlsx';
  5.  
  6. const StoreMapScreen = () => {
  7.   const [stores, setStores] = useState([]);
  8.  
  9.   useEffect(() => {
  10.     // Đọc dữ liệu từ file Excel khi màn hình được load
  11.     readExcelData();
  12.   }, []);
  13.  
  14.   const readExcelData = async () => {
  15.     try {
  16.       const fileUri = 'path_to_your_excel_file/data.xlsx';
  17.       const workbook = XLSX.readFile(fileUri);
  18.       const sheetName = workbook.SheetNames[0];
  19.       const sheet = workbook.Sheets[sheetName];
  20.       const data = XLSX.utils.sheet_to_json(sheet);
  21.       setStores(data);
  22.     } catch (error) {
  23.       console.error('Error reading Excel file:', error);
  24.     }
  25.   };
  26.  
  27.   const updateStoreInfo = (storeId, newInfo) => {
  28.     // Cập nhật thông tin cửa hàng với ID cho trước
  29.     // Cập nhật dữ liệu stores và cập nhật trực tiếp lên bản đồ
  30.   };
  31.  
  32.   return (
  33.     <View  flex: 1 }}>
  34.       <MapView
  35.           flex: 1 }}
  36.          initialRegi
  37.           latitude: 37.78825,
  38.           longitude: -122.4324,
  39.           latitudeDelta: 0.0922,
  40.           longitudeDelta: 0.0421,
  41.         }}
  42.       >
  43.         {stores.map(store => (
  44.           <Marker
  45.             key={store.id} // Giả sử cửa hàng có trường id
  46.             coordinate={{ latitude: store.latitude, longitude: store.longitude }} // Giả sử các cửa hàng có thông tin vị trí
  47.             title={store.name}
  48.              descripti
  49.               => console.log('Marker pressed:', store)}
  50.           />
  51.         ))}
  52.       </MapView>
  53.       <View  position: 'absolute', bottom: 20, left: 20 }}>
  54.         <Button title="Update Store Info"  => updateStoreInfo(storeId, newInfo)} />
  55.       </View>
  56.     </View>
  57.   );
  58. };
  59.  
  60. export default StoreMapScreen;
  61.  

Replies to Untitled rss

Title Name Language When
Re: Untitled thoai text 1 Month ago.