【问题标题】:Determine user location on iOS Simulator with React Native app using Geolocation API使用 Geolocation API 使用 React Native 应用程序确定 iOS 模拟器上的用户位置
【发布时间】:2015-09-03 14:34:59
【问题描述】:

如何让将在 iOS 模拟器上运行的应用获取地理位置。

目前我只能得到我为 getCurrentPosition() 或 watchPosition() 的错误回调编写的错误输出。

我的一个组件中有这段代码:

 componentDidMount: function(){
    var geo = navigator.geolocation;
    var positionOptions = {
      enableHighAccuracy: true,
      timeout: 3000,
      maximumAge: 0,
    };
    var success = function(position){
      this.setState({
        region: {
          latitude: position.coords.latitude,
          longitude: position.coords.longitude,
        },
      });
    };
    var error = function(error){
      alert('error watchposition:', error.code);
    };
    var watchID = geo.watchPosition(success, error, positionOptions);
    // geo.getCurrentPosition(success, error, positionOptions);
  },

【问题讨论】:

    标签: react-native


    【解决方案1】:

    确保您在模拟器的调试菜单中有正确的自定义位置。

    还要确保在模拟器中为您的应用启用定位服务。

    【讨论】:

    • 我在模拟器上启用了定位服务。
    • 自定义位置的坐标是什么?
    • 由于我已经放弃了一段时间的设置,我不记得其中的自定义位置。一旦我再次开始工作,我就知道了。这里的问题是ios模拟器可以获取真实位置吗?
    • 也许它不应该在我认为有可能的模拟器上工作。
    猜你喜欢
    • 2021-07-22
    • 1970-01-01
    • 1970-01-01
    • 2021-11-20
    • 2023-03-13
    • 2019-12-21
    • 2019-12-21
    • 2017-10-18
    • 2021-10-05
    相关资源
    最近更新 更多