Ich entwerfe eine reag -native App für Android. Der Zweck der Anwendung ist es, ein Bild hochzuladen und auf der Karte basierend auf den in den EXIF -Informationen gespeicherten GPS -Koordinaten zu platzieren. Derzeit scheint die Anwendung die GPS -Koordinaten auf 0 zurückzusetzen. Ich bin mir nicht sicher, warum und möchte einige Eingaben. < /P>
Hier ist mein App.js -Code. Wenn Sie etwas anderes sehen möchten, lassen Sie es mich wissen! < /P>
Ich entwerfe eine reag -native App für Android. Der Zweck der Anwendung ist es, ein Bild hochzuladen und auf der Karte basierend auf den in den EXIF -Informationen gespeicherten GPS -Koordinaten zu platzieren. Derzeit scheint die Anwendung die GPS -Koordinaten auf 0 zurückzusetzen. Ich bin mir nicht sicher, warum und möchte einige Eingaben. < /P> Hier ist mein App.js -Code. Wenn Sie etwas anderes sehen möchten, lassen Sie es mich wissen! < /P> [code]import React, { useEffect, useState } from 'react'; import { View, StyleSheet, Image, Text, TouchableOpacity, Modal, useWindowDimensions, Alert, Platform } from 'react-native'; import MapView, { Marker } from 'react-native-maps'; import * as MediaLibrary from 'expo-media-library'; import * as ImagePicker from 'expo-image-picker'; import * as Location from 'expo-location'; import * as FileSystem from 'expo-file-system';
// Example baked-in image URIs (images stored in your app's assets folder) const bakedInImages = [ { id: 'baked-1', uri: require('./assets/images/king_tee.jpg'), // Local image latitude: 37.7749, longitude: -122.4194, }, { id: 'baked-2', uri: require('./assets/images/winter_photo.png'), // Local image latitude: 34.0522, longitude: -118.2437, }, ];
// Load photos with location from the media library try { console.log("Fetching assets from media library..."); const assets = await MediaLibrary.getAssetsAsync({ mediaType: 'photo', first: 20, }); console.log(`Found ${assets.assets.length} assets`);
const photosWithGPS = [];
for (let asset of assets.assets) { try { // Get full asset info to ensure we have location data const assetInfo = await MediaLibrary.getAssetInfoAsync(asset);
// Check if the asset has location data if (assetInfo.location) { console.log(`Asset ${assetInfo.id} has location data:`, assetInfo.location); photosWithGPS.push({ id: assetInfo.id, uri: assetInfo.uri, latitude: assetInfo.location.latitude, longitude: assetInfo.location.longitude, }); } } catch (error) { // Skip this asset if there's an error console.log('Error processing asset:', error); } }
console.log(`Found ${photosWithGPS.length} photos with GPS data`); setMarkers([...photosWithGPS, ...bakedInImages]); // Combine device photos and baked-in images } catch (error) { console.error('Error loading media library:', error); } } catch (error) { console.error("Error during initialization:", error); } finally { setIsLoading(false); } };
requestPermissionsAndFetchAssets(); }, []);
// Function to attempt to extract EXIF/location data from an image const tryGetImageLocation = async (imageUri) => { console.log("Attempting to extract location from image:", imageUri);
try { // Try to get the file info first const fileInfo = await FileSystem.getInfoAsync(imageUri); console.log("File info:", fileInfo);
if (!fileInfo.exists) { console.log("File does not exist"); return null; }
// For Android with the proper permissions, we can try to get the asset if (Platform.OS === 'android') { try { // Try to find the asset in the media library const uriParts = imageUri.split('/'); const filename = uriParts[uriParts.length - 1];
// Search for the asset const query = filename.split('.')[0]; // Remove extension for better search const mediaAssets = await MediaLibrary.getAssetsAsync({ first: 10, sortBy: [['creationTime', false]], });
// Find the matching asset for (const asset of mediaAssets.assets) { try { const assetInfo = await MediaLibrary.getAssetInfoAsync(asset); if (assetInfo.uri.includes(query) || imageUri === assetInfo.uri) { console.log("Found matching asset with location:", assetInfo.location); if (assetInfo.location) { return { latitude: assetInfo.location.latitude, longitude: assetInfo.location.longitude }; } } } catch (error) { console.log("Error checking asset:", error); } } } catch (error) { console.log("Error searching media library:", error); } }
// If we get here, we couldn't find location data console.log("No location data found for this image"); return null; } catch (error) { console.error("Error extracting location data:", error); return null; } };
// Handle opening the modal for full-screen image const openModal = (image) => { setSelectedImage(image.uri); setModalVisible(true); };
// Handle map press for manual location selection const handleMapPress = (event) => { if (manualLocationMode && pendingImage) { // Get coordinates from the press event const { coordinate } = event.nativeEvent;
// Create a new marker with the selected image and the tapped location const newMarker = { id: pendingImage.uri, uri: pendingImage.uri, latitude: coordinate.latitude, longitude: coordinate.longitude, };
// Add the new marker setMarkers(prevMarkers => [...prevMarkers, newMarker]);
// Reset manual mode and pending image setManualLocationMode(false); setPendingImage(null);
// Show confirmation Alert.alert("Image Added", "The image has been added to the map at the selected location."); } };
const handleImagePicker = async () => { // Request permission for media library console.log("Requesting media library permissions..."); const permissionResult = await ImagePicker.requestMediaLibraryPermissionsAsync( Platform.OS === 'android' ? true : false );
if (permissionResult.granted === false) { Alert.alert('Permission required', 'Permission to access media library is required!'); return; }
let latitude = pickedAsset.exif.GPSLatitude; let longitude = pickedAsset.exif.GPSLongitude; console.log(pickedAsset.exif); console.log(pickedAsset.exif.GPSLatitude); console.log(pickedAsset.exif.GPSLongitude);
console.log("Found location in EXIF data:", { latitude, longitude });
location = { latitude, longitude }; }
// Second attempt: Try to find location metadata using our helper function if (!location) { console.log("No EXIF location found, trying alternative methods..."); location = await tryGetImageLocation(pickedAsset.uri); }
// If we found location data, create the marker if (location) { console.log("Successfully found location data:", location);
// Add the marker setMarkers(prevMarkers => [...prevMarkers, newMarker]);
// Focus map on the new marker setMapRegion({ latitude: location.latitude, longitude: location.longitude, latitudeDelta: 0.01, longitudeDelta: 0.01, });
Alert.alert( "Success", "Image added to map with its original location data!" ); } else { // No location data found, offer manual placement console.log("No location data found, offering manual placement options");
Alert.alert( "No Location Data", "This image doesn't have location data. How would you like to place it?", [ { text: "Use My Current Location", onPress: () => { // Create marker at current location const newMarker = { id: pickedAsset.uri, uri: pickedAsset.uri, latitude: currentLocation.latitude, longitude: currentLocation.longitude, };
// Add the new marker setMarkers(prevMarkers => [...prevMarkers, newMarker]);
// Focus map on the new marker setMapRegion({ latitude: currentLocation.latitude, longitude: currentLocation.longitude, latitudeDelta: 0.01, longitudeDelta: 0.01, }); } }, { text: "Tap on Map to Place", onPress: () => { // Enter manual location mode setPendingImage(pickedAsset); setManualLocationMode(true);
// Show instructions Alert.alert( "Tap on Map", "Tap anywhere on the map to place your image at that location." ); } }, { text: "Cancel", style: "cancel" } ] ); } } };
return (
{markers.map((marker) => ( openModal(marker)} >
))}
{/* Modal for Full-Screen Image */} {selectedImage && (
Ich entworfene App, mit der Daten aus dem Hochladen von User Zip -Datei produziert werden. Ich frage mich, ob es in Ordnung ist, es ohne Backend zu behandeln. Ich möchte keine Daten speichern. In...
Ich möchte Text aus Blur Image 1 mit dem folgenden Code extrahieren.
Ich bin neu in diesem und muss diese Aufgabe erledigen. Für mich? #Pytesseract.pytesseract.tSeract_cmd = r'c: \ Programmdateien \...
reagieren nativ standardmäßig gedrückte Protokolle mit allen Netzwerkanforderungs- und Anwendungsprotokollen auf ADB, die beim Griff mit - ADB -logcat *: s reactnativejs: v uns alle Protokolle von...
Ich versuche, Latex -Mathematikgleichungen in meiner nativen React -Anwendung anzuzeigen. Zunächst habe ich versucht, React-Native-Mathjax-Svg und React-Native-Math-View zu verwenden, aber keiner von...
Ich versuche, Latex -Mathematikgleichungen in meiner nativen React -Anwendung anzuzeigen. Zunächst habe ich versucht, React-Native-Mathjax-Svg und React-Native-Math-View zu verwenden, aber keiner von...