Navigator.geolocation仅适用于Safari浏览器,不适用于Chrome浏览器

时间:2019-09-05 22:12:22

标签: javascript reactjs google-chrome geolocation

地理位置仅询问用户是否可以在野生动物园中使用,并且如果回答“是”,则页面工作正常。在谷歌浏览器中,它只是说正在加载而从未询问。在开发过程中,它在chrome中效果很好。我不知道这个问题。现场演示:https://todine.herokuapp.com

getLocation = () => {
    navigator.geolocation.getCurrentPosition(
      position => {
        this.setState({
          latitude: position.coords.latitude,
          longitude: position.coords.longitude,
          loaded: true
        });
        if (this.state.loaded === true) {
          this.getRestaurants(this.state.latitude, 
          this.state.longitude);
        }
      },
      error =>
        this.setState({
          error: error.message
        }),
      { enableHighAccuracy: false, timeout: 5000, maximumAge: 10000 }
    );
  };

1 个答案:

答案 0 :(得分:-1)

您的代码看起来不错。 您应该查看页面中浏览器的位置设置。

enter image description here