I am currently working on an app using React Native built with Expo.
I have been trying to register and update some columns, but I am encountering issues.
Below is a snippet of my source code:
import * as Location from 'expo-location';
const URL = {
CREATE_CURRENT_LOCATION:'https://sayhellotobike-native-ios-default-rtdb.firebaseio.com'
}
export const requestLocationPermission = async (setLocationCallBack,myCurrentLocationArray,setIsMapReady) => {
try {
const { status } = await Location.requestForegroundPermissionsAsync();
if (status === 'granted') {
// Execute the process to get current location
getCurrentLocation(setLocationCallBack,myCurrentLocationArray,setIsMapReady);
} else {
console.log('Location permission denied');
}
} catch (error) {
console.error('Error requesting location permission:', error);
}
};
export const getCurrentLocation = async (setLocationCallBack,myCurrentLocationArray,setIsMapReady) => {
try {
const { coords } = await Location.getCurrentPositionAsync({});
const { latitude, longitude } = coords;
setLocationCallBack({ ...myCurrentLocationArray,latitude, longitude });
setIsMapReady(true);
writeMyLocationData(URL.CREATE_CURRENT_LOCATION,0,latitude,longitude)
} catch (error) {
console.error('Error getting current location:', error);
}
};
import { ref, set } from "firebase/database";
import { database } from '../firebaseConfig';
export const writeMyLocationData = async (url, userId, latitude, longitude) => {
console.log("Writing data:", url, userId, latitude, longitude);
let params = {
user_id: userId,
latitude: latitude,
longitude: longitude[enter image description here](https://i.sstatic.net/3GnaeJSl.png)
}
try{
set(ref(database, url + 'location'), params
)
}catch(error){
console.error(error)
}finally{
console.log("Process sent.")
}
console.log("fetchLocation",fetchLocation)
}
I suspect that there might be an issue with the path due to special characters.
The error code states:
Error: child failed: path argument was an invalid path = "https:
your text
//sayhellotobike-native-ios-default-rtdb.firebaseio.com/location/latitude". Paths must be non-empty strings and can't contain ".", "#", "$", "[", or "]"
I have tried changing the path to:
/location
/location/latitude
location
/
And various other options.
- I have also included an image and firebase configuration. enter image description here
import { initializeApp } from 'firebase/app';
import { getAuth } from "firebase/auth"
import { getDatabase }from "firebase/database";
const firebaseConfig = {
apiKey: "AIzaSyCe2ZqMbYldfc-M7hXEBBSNJHnJy5gMig4",
authDomain: "sayhellotobike-native-ios.firebaseapp.com",
databaseURL: "https://sayhellotobike-native-ios-default-rtdb.firebaseio.com",
projectId: "sayhellotobike-native-ios",
storageBucket: "sayhellotobike-native-ios.appspot.com",
messagingSenderId: "94237205998",
appId: "1:94237205998:web:879feeef3ddb781d3e1aff",
measurementId: "G-ZLR4NQ9XG4"
};
const app = initializeApp(firebaseConfig);
export const auth = getAuth(app);
export const database = getDatabase(app);