【问题标题】:getting an error No ViewManager defined for class RCTRawText收到错误没有为类 RCTRawText 定义 ViewManager
【发布时间】:2018-05-11 18:41:27
【问题描述】:

我正在尝试使用 geolocation.getcurrentposition,但出现错误。以下是错误的屏幕截图:

下面是我的 App.Js 代码:

import React, { Component } from 'react';
import { View, Text } from 'react-native';

class GeolocationExample extends Component {
  constructor(props) {
    super(props);

    this.state = {
      latitude: null,
      longitude: null,
      error: null,
    };
  }

  componentDidMount() {
    // Instead of navigator.geolocation, just use Geolocation.
    if (hasLocationPermission) {
        Geolocation.getCurrentPosition(
            (position) => {
                console.log(position);
            },
            (error) => {
                // See error code charts below.
                console.log(error.code, error.message);
            },
            { enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 }
        );
    }
}

  render() {
    return (
      <View style={{ flexGrow: 1, alignItems: 'center', justifyContent: 'center' }}>
        <Text>Latitude: {this.state.latitude}</Text>
        <Text>Longitude: {this.state.longitude}</Text>
        {this.state.error ? <Text>Error: {this.state.error}</Text> : null}
      </View>
    );
  }
}

export default GeolocationExample;

我还对 MainActivity.Java 文件做了一些修改。以下是我在 MainActivity 的依赖项部分所做的更改。爪哇

import com.agontuk.RNFusedLocation.RNFusedLocationPackage;
@Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
         // new MainReactPackage()
          new RNFusedLocationPackage()
      );
    }

使用 getcUrrentposition 时,我的经度和纬度超时,这就是原因,我正在使用解决方法。此解决方法是安装 react-native-geolocation -service。我使用的 google play 服务版本是 12.2.21。下面是图片:

我还在 build.gradle 中添加了依赖项。我在 build.gradle 中插入了当前的 google play 服务版本

  compile(project(':react-native-geolocation-service')) {
    exclude group: 'com.google.android.gms', module: 'play-services-location'
}
compile 'com.google.android.gms:play-services-location:12.2.21'

当我试图获取用户当前位置的经度和纬度时,上面的代码超时。我进行了这些更改,以便我的 android 手机开始显示经度和纬度而不会超时。我不确定这个错误来自哪里。该错误未显示任何行号。

任何帮助将不胜感激

【问题讨论】:

    标签: react-native react-android


    【解决方案1】:

    同样的问题,但是当我尝试自动链接时,我在 Android Studio 中收到了该软件包的警告

    com.agontuk.RNFusedLocation

    已弃用

    所以我认为 react-native-geolocation-service 是错误的

    【讨论】:

      猜你喜欢
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-11
      • 2021-02-11
      • 2019-12-01
      相关资源
      最近更新 更多