【问题标题】:Android Emulator React Native Geolocation not workingAndroid Emulator React Native Geolocation 不起作用
【发布时间】:2021-03-21 06:23:43
【问题描述】:

我正在使用 Windows 在 android studio 上处理地理定位代码。但由于某种原因,我现在的位置没有被选中。我尝试使用其他选项,例如 enableHighAccuracy:false。还尝试运行 Telnet,并应用 geo fix long lat,但没有任何反应。

请查看我在博览会零食上测试时实际工作的相关代码。

  findCurrentLocationAsync=()=>{

      navigator.geolocation.getCurrentPosition(
          (position) => {
         //   console.log(position);
            let lat=position.coords.latitude;
            let long=position.coords.longitude;
            
            this.setState({
              markerPosition: {
                lat: lat,
                lng: long
            },
            mapPosition: {
                latitude: lat,
                longitude: long,
                latitudeDelta: 0.0922,
                longitudeDelta: 0.0421,
            }
            });

             Geocoder.from( this.state.mapPosition.latitude , this.state.mapPosition.longitude ).then(
              response => {
                  const address = response.results[0].formatted_address,
                        addressArray =  response.results[0].address_components,
                        city = this.getCity( addressArray ),
                        area = this.getArea( addressArray ),
                        state = this.getState( addressArray );
                        zip = this.getZip( addressArray );
      
                console.log(addressArray)
      
                  this.setState( {
                      address: ( address ) ? address : '',
                      area: ( area ) ? area : '',
                      city: ( city ) ? city : '',
                      state: ( state ) ? state : '',
                      zip: ( zip ) ? zip : '',
                  } )
              },
              error => {
              //  console.error( error );
              }
          )

          },
         
         //{ enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 },
         ///()=>console.log(lat)  
      );

    
     };

非常感谢您的建议

谢谢 萨尔

【问题讨论】:

  • 也发布有关代码。
  • 请检查。代码有效。但不选择当前位置。刚刚粘贴了相关代码。谢谢
  • 您使用了 expo-location。但我认为它更多的是andorid问题。你看到使用 navigator.geolocation.getCurrentPosition 的问题了吗?

标签: javascript reactjs react-native android-studio react-redux


【解决方案1】:

如果您没有,请使用 android emu 设置设置位置。 Android 模拟器右侧有设置栏。单击“三点”按钮并标记您要模拟的位置,然后设置位置。

如果您完成了这些步骤,请忽略它。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2020-12-20
  • 2021-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-30
相关资源
最近更新 更多