我正在通过 Expo 的 React Native 构建开发一个应用程序。
我尝试注册和更新一些专栏,但这些效果不佳。
我的源代码如下
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') {
// 位置情報の取得処理を実行する
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'; // Firebaseのデータベースを正しくインポートする必要があります
export const writeMyLocationData = async (url, userId, latitude, longitude) => {
console.log("書き込み開始:", 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("処理を送りました。")
}
console.log("fetchLocation",fetchLocation)
// .then(() => {
// console.log("書き込み成功:", url, userId, latitude, longitude);
// })
// .catch((error) => {
// console.error("書き込みエラー:", error);
// });
}
我猜路径可能是错误的特殊字符。
错误代码如下。我确信我不使用like。
错误:子项失败:路径参数是无效路径=“https:
//sayhellotobike-native-ios-default-rtdb.firebaseio.com/location/latitude”。路径必须是非空字符串,并且不能包含“.”、“#”、“$”、“[”或“]”your text
我尝试更改路径,例如
/location
/location/latitude
location
/
等等。
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);