React Native iOS 中的地理定位 [英] Geolocation in React Native iOS
本文介绍了React Native iOS 中的地理定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在我的应用程序中访问 navigator.geolocation.
I am trying to access navigator.geolocation in my application.
我还在 info.plist 中设置了NSLocationWhenInUseUsageDescription".
I have also set "NSLocationWhenInUseUsageDescription" in my info.plist.
但是,当我运行我的应用程序时,它会抛出一个错误,指出未定义不是一个对象(正在评估 navigator.geolocation.getCurrentPosition)".
But, when I run my app, It throws an error saying "undefined is not an object (evaluating 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,
};
}
谁能告诉我我做错了什么?
Can anybody tell what I am doing wrong ?
推荐答案
你必须添加
Xcode 中的 NSLocationWhenInUseUsageDescription
NSLocationWhenInUseUsageDescription in Xcode
和
Xcode 中的 libRCTGeolocation.a
libRCTGeolocation.a in Xcode
这篇关于React Native iOS 中的地理定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文