react-native - React Native iOS 中的地理定位

标签 react-native

我正在尝试在我的应用程序中访问 navigator.geolocation。

我还在我的 info.plist 中设置了“NSLocationWhenInUseUsageDescription”。

但是,当我运行我的应用程序时,它会抛出一个错误,提示“未定义不是对象(评估 navigator.geolocation.getCurrentPosition)”。

这是我的代码 -

import React, { Component } from 'react';
import {
  AppRegistry,
  Image,
  ListView,
  StyleSheet,
  Text,
  Navigator,
  TouchableHighlight,
  Alert,
  TouchableOpacity,
  View
} from 'react-native';
import Spinner from 'react-native-loading-spinner-overlay'
var GiftedSpinner = require('react-native-gifted-spinner');
var GLOBAL = require('./Globals');
var stateName;
var latitude;
var longitude;

class PersonByLocationPage extends Component {

  constructor(props) {
    super(props);
    this.data = this.props.data;

     navigator.geolocation.getCurrentPosition(
                        (position) => {
                           var crd = position.coords;
                           latitude = crd.latitude;
                           longitude = crd.longitude;
                            // alert(latitude);
                            // alert(longitude);
                          },
                          (error) => alert(error.message),
                          {enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
                      );


    this.REQUEST_URL = 'sample';


    this.state = {
      dataSource: new ListView.DataSource({
        rowHasChanged: (row1, row2) => row1 !== row2,
      }),
      loaded: false,
      networkError: false,
    };
  }

有人能告诉我我做错了什么吗?

最佳答案

  1. 将 RCTGeolocation.xcodeproj 拖到 Libraries 文件夹中。
  2. 在项目导航器中点击您的项目。
  3. 点击“TARGETS”下的“YOUR_PROJECT_NAME”。
  4. 单击“构建阶段”选项卡。在“链接二进制文件与库”阶段,
  5. 单击加号图标并选择 libRCTGeolocation.a 从出现的模式列表中。

这应该就是您所需要的。让我知道这是否适合您。

关于react-native - React Native iOS 中的地理定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37996054/

相关文章:

webview - (React Native) 将本地 HTML 文件加载到 WebView 中

javascript - 从数组中提取父 Node

ios - 如何在 React native 中集成 unity?

reactjs - React Native 和 Redux : Require cycle (how to get rid of it? )

react-native - 在根项目 'installRelease' 中找不到任务 'ReactNativeStarter'。一些候选人是 : 'uninstallRelease'

javascript - 获取货币符号的特殊文本字符的 HTML 实体代码

android - 让 Android RecyclerView 更新 React Native 组件内的 View

android - 为 android 和 ios react native 指纹认证

android - 在带有覆盖的背景图像上方渲染组件

firebase - 使用 FlatList (React Native) 时出现错误 : Warning: Each child in an array or iterator should have a unique "key" prop. %s%s