【问题标题】:Vue native Geolocation Error _expo.Permissions.askAsync undefinedVue原生地理定位错误_expo.Permissions.askAsync未定义
【发布时间】:2020-04-03 07:13:35
【问题描述】:

我学习 Vue Native 已经有一段时间了。我正在浏览https://vue-native.io 中提供的文档并一一尝试。当我来到 Geolocation 部分时,我想试用 expo permision api。我收到了这个错误

undefined 不是对象(评估 '_expo.Permissions.askAsync')

这是我的代码

 <template>
  <view class="container">
    <text>Location:</text>
    <text>{{location.latitude}}</text>
    <touchable-opacity :on-press="getLocation" >
        <text>get location</text>
    </touchable-opacity>
  </view>
</template>

 <script>

import { Constants, Location, Permissions } from "expo";

export default {
  data: function() {
    return {
      location: {},
      errorMessage: ""
    };
  },
  methods: {
    getLocation: function() {
      Permissions.askAsync(Permissions.LOCATION).then(status => {
        if (status !== "granted") {
          errorMessage = "Permission to access location was denied";
        }
        Location.getCurrentPositionAsync({}).then(location1 => {
          location = location1;
        });
      }).catch((err)=>{
        console.log(err);
     });
    }
  }
};
</script>
<style>
.container {
  background-color: white;
  align-items: center;
  justify-content: center;
  flex: 1;
}
.text-color-primary {
  color: blue;
}
</style>

错误必须来自 getLocation 函数并且与 expo 权限有关。你能告诉我这里可能是什么问题吗?谢谢

【问题讨论】:

    标签: javascript react-native expo native vue-native


    【解决方案1】:

    试试这个:

    const _this = this;
    Permissions.askAsync(Permissions.LOCATION)
        .then( status => {
            if (status !== "granted") {
                errorMessage = "Permission to access location was denied";
            } else {
                _this.Location.getCurrentPositionAsync()
                   .then(location1 => {
                      _this.location = location1;
                   })
            }
        })
        .catch( error => { console.log('error');})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-17
      • 2018-04-03
      • 1970-01-01
      相关资源
      最近更新 更多