【发布时间】:2022-10-04 13:52:31
【问题描述】:
我正在使用react-native-geolocation-service,我有这样的功能来获取坐标。然后通过 Geocoder api 通过坐标获取城市。我通过react-native-permissions查看权限状态:
export const getCity = async (dispatch: Dispatch<any>) => {
const granted = await check(PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION);
if (granted === RESULTS.DENIED) {
await PermissionsAndroid.request(PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION, {
buttonNegative: undefined,
buttonNeutral: undefined,
buttonPositive: '',
title: 'Access',
message: 'give access',
});
}
if (granted === RESULTS.GRANTED || granted === RESULTS.LIMITED) {
Geolocation.getCurrentPosition(
position => {
const coords: Coords = {
Longitude: position.coords.longitude,
Latitude: position.coords.latitude,
};
dispatch(thunks.geocoder.getGeocoderInfo(coords));
Alert.alert('coords', `${coords.Latitude}, ${coords.Longitude}`);
},
error => Alert.alert('Error', `Error ${error.message}`),
{
enableHighAccuracy: false,
timeout: 20000,
maximumAge: 3600000,
},
);
}
};
因此,当我的应用程序启动时,我授予它权限,然后它就关闭了。我还添加了访问AndroidManifest.xml:<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>。然后我使用UseEffect() 在我的组件中调用这个函数
【问题讨论】:
-
将手机插入计算机,打开 Android Studio 并再次运行您的应用。在 LogCat 窗口中,您应该会看到导致应用崩溃的错误。您可以使用该错误更新您的问题,然后人们会更容易帮助您
-
@CarlosJ Tanks 供您发表评论。我会尝试