Opcja A
- User
Opcja A
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Opcja A
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Wspaniale! Zacznijmy od podstawowej architektury aplikacji z funkcjonalnością śledzenia GPS i wyświetlenia map. Poniżej krok po kroku implementacji w React Native:
Utwórz nowy projekt React Native:
npx react-native init SportApp
cd SportApp
Zainstaluj niezbędne pakiety:
npm install react-native-maps sqlite3 react-native-sqlite-storage @react-native-community/geolocation
Dodaj uprawnienia do GPS w systemie:
AndroidManifest.xml dodaj:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Info.plist dodaj:
<key>NSLocationWhenInUseUsageDescription</key>
<string>Aplikacja wymaga dostępu do lokalizacji</string>
Użyjemy biblioteki react-native-maps z tile-ami z OpenStreetMap.
W głównym komponencie (App.js) zaimportuj potrzebne moduły:
import MapView, { PROVIDER_GOOGLE } from 'react-native-maps';
import Geolocation from '@react-native-community/geolocation';
Ustaw mapę z tile-ami OpenStreetMap:
const MapScreen = () => {
const [region, setRegion] = useState({
latitude: 52.2297,
longitude: 21.0122,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
});
return (
<MapView
provider={PROVIDER_GOOGLE} // Ignorowane - używamy własnych tile'ów
style={{ flex: 1 }}
region={region}
// Własne tiley OpenStreetMap
tileSize={256}
tiles={[
'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
]}
/>
);
};
const [position, setPosition] = useState(null);
const [routePoints, setRoutePoints] = useState([]);
useEffect(() => {
// Rozpoczęcie śledzenia
const watchID = Geolocation.watchPosition(
(position) => {
const { coords } = position;
setPosition(coords);
// Zapisz punkt do bazy danych
savePointToDatabase(coords);
setRoutePoints(prev => [...prev, coords]);
},
(error) => console.log(error),
{ enableHighAccuracy: true, timeout: 15000, maximumAge: 1000 }
);
return () => Geolocation.clearWatch(watchID);
}, []);
Utwórz bazę danych SQLite do przechowywania tras i punktów:
import SQLite from 'react-native-sqlite-storage';
// Inicjalizacja bazy
const db = SQLite.openDatabase(
{
name: 'sportapp.db',
location: 'default'
},
() => console.log("Baza otwarta!"),
error => console.error("Błąd inicjalizacji: ", error)
);
// Utwórz tabele
db.transaction((tx) => {
tx.executeSql(
'CREATE TABLE IF NOT EXISTS routes (id INTEGER PRIMARY KEY, start_time TEXT);',
[]
);
tx.executeSql(
'CREATE TABLE IF NOT EXISTS points (id INTEGER PRIMARY KEY, route_id INTEGER, latitude REAL, longitude REAL, timestamp TEXT, FOREIGN KEY(route_id) REFERENCES routes(id));',
[]
);
});
Funkcja zapisująca punkty:
const savePointToDatabase = (coords) => {
const now = new Date().toISOString();
// Zapisz współrzędne w bazie
db.transaction(tx => {
tx.executeSql(
'INSERT INTO points (route_id, latitude, longitude, timestamp) VALUES (?, ?, ?, ?)',
[currentRouteID, coords.latitude, coords.longitude, now]
);
});
};
{routePoints.length > 1 && (
<MapView.Polyline
coordinates={routePoints.map(p => ({
latitude: p.latitude,
longitude: p.longitude
}))}
strokeColor="#FF0000"
strokeWidth={3}
/>
)}
npx react-native run-android
# lub
npx react-native run-ios
Czy chciałbyś teraz:
Wybierz, gdzie kontynuować! 😊