Cureent 用戶位置獲取本地反應
uj5u.com熱心網友回復:
您可以使用 Expo 訪問該位置,如下代碼片段所示。
import * as Location from "expo-location";
export const hasLocationServiceEnable = async () =>
await Location.hasServicesEnabledAsync();
const getUserLocation = async () => {
let result = null;
const isLocationAccessEnabled = await hasLocationServiceEnable();
/** Discard request coordinates when user location disabled. This required to avoid
* continuously request location in contrary to the user preference
*/
if (!isLocationAccessEnabled) {
return result;
} else {
// Request location access permission
let { status } = await Location.requestForegroundPermissionsAsync();
if (status !== "granted") {
return result;
} else {
try {
let { coords } = await Location.getCurrentPositionAsync({});
result = coords || null;
} catch (error) {
console.error(error)
}
return result;
}
}
};
export default getUserLocation;
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/427071.html
標籤:反应式 谷歌地图 谷歌地图 api-3 谷歌地图标记 地图方向
