我正在使用博覽會位置來請求用戶許可以及獲取他們的緯度/經度坐標。我正在努力在互聯網上找到一些有見地的例子,這讓我在他們的檔案中找到了。
使用他們提供的示例,我正在請求權限并記錄一個看起來像 LocationObjectCoords 的回傳值,您可以看到它是在允許權限后呈現的。查看檔案時,特別是 getCurrentPositionAsync;看起來它回傳 LocationObject ,它只是坐標和它們被記錄的時間。
我怎樣才能專門回傳緯度和經度,而不是 LocationObjectCoords 中包含的所有其他內容?
下面是我的代碼以及我的代碼的一個簡單示例。作為IOS運行。
const [location, setLocation] = useState(null);
const [errorMsg, setErrorMsg] = useState(null);
useEffect(() => {
(async () => {
let { status } = await Location.requestForegroundPermissionsAsync();
if (status !== 'granted') {
setErrorMsg('Permission to access location was denied');
return;
}
let location = await Location.getCurrentPositionAsync({});
setLocation(location);
})();
}, []);
let text = 'Waiting..';
if (errorMsg) {
text = errorMsg;
} else if (location) {
text = JSON.stringify(location);
}
return (
<View style={styles.container}>
<Text style={styles.paragraph}>{text}</Text>
</View>
);
}
uj5u.com熱心網友回復:
一切都在你的location變數上,你只需要單獨保存你的latitude和longitude。看看這個,作業正常:https ://snack.expo.dev/SXAmeusSa
希望這對你有用
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/422641.html
標籤:
