首页 > 解决方案 > 移动设备上的 navigator.geolocation 错误

问题描述

这是来自 React 应用程序的片段。应用程序:https ://perfect-sunset.herokuapp.com/

地理位置在桌面上运行良好。在 iPhone 和 Android 上,它会立即引发错误警报。手机上的定位服务已开启。

非常感谢任何帮助!谢谢你!

 componentDidMount() {

    navigator.geolocation.getCurrentPosition(
          (position) => {
            let lat = position.coords.latitude
            let lng = position.coords.longitude
            console.log("getCurrentPosition Success " + lat + lng);
            this.setState({
              location: {
                latitude: lat,
                longitude: lng
              }
            })
            ///..does more stuff..///
          },
          (error) => {
            alert('geolocation error');
            this.setState({
              geoLocatorStatus:  'You geolocation is OFF. Please, use ZIP code.'
            })
            console.error(JSON.stringify(error))
          }, {
            enableHighAccuracy: true,
            timeout: 20000,
            maximumAge: Infinity
          }
        )
}

标签: javascriptiosreactjsmobilegeolocation

解决方案


推荐阅读