当我请求获取位置的权限时,如果设备的位置已关闭,我的android应用就会崩溃。我怎样才能解决这个问题?这是我的import django_filters
from app.models import Cars
class CarsFilter(django_filters.FilterSet):
class Meta:
model = Recommendation
fields = ["area", "car_type", "week_num", "released"]
函数:
getLocation()
我在 getLocation = () => {
try {
navigator
.geolocation
.getCurrentPosition(position => {
const location = JSON.stringify(position);
this.writeItemToStorage(position.coords.latitude,position.coords.longitude);
this.setState({location: location, latitude: position.coords.latitude, longitude: position.coords.longitude});
}, error => Alert.alert(error.message), {
enableHighAccuracy: false,
timeout: 20000,
maximumAge: 10000
});
} catch(e) {
alert(e);
}
}
中设置了 lat 和 long