你需要在 info.plist 中添加 NSLocationWhenInUseUsageDescription
键来定位,当你用 react-native init
来创建一个项目时,默认情况下定位是能够使用的。
定位遵循 MDN 规范:
https://developer.mozilla.org/en-US/docs/Web/API/Geolocation
static getCurrentPosition(geo_success: Function, geo_error?: Function, geo_options?: Object)
static watchPosition(success: Function, error?: Function, options?: Object)
static clearWatch(watchID: number)
static stopObserving()
Edit on GitHub
"use strict";var React = require("react-native");var { StyleSheet, Text, View, } = React; exports.framework = "React"; exports.title = "Geolocation"; exports.description = "Examples of using the Geolocation API."; exports.examples = [ { title: "navigator.geolocation", render: function(): ReactElement { return <GeolocationExample />; }, } ];var GeolocationExample = React.createClass({ watchID: (null: ?number), getInitialState: function() { return { initialPosition: "unknown", lastPosition: "unknown", }; }, componentDidMount: function() { navigator.geolocation.getCurrentPosition( (initialPosition) => this.setState({initialPosition}), (error) => console.error(error) ); this.watchID = navigator.geolocation.watchPosition((lastPosition) => { this.setState({lastPosition}); }); }, componentWillUnmount: function() { navigator.geolocation.clearWatch(this.watchID); }, render: function() { return ( <View> <Text> <Text style={styles.title}>Initial position: </Text> {JSON.stringify(this.state.initialPosition)} </Text> <Text> <Text style={styles.title}>Current position: </Text> {JSON.stringify(this.state.lastPosition)} </Text> </View> ); } });var styles = StyleSheet.create({ title: { fontWeight: "500", }, });
IOS 故事板(Storyboards)简介 Storyboards在 iOS 5 中才有介绍,当我们用Storyboards时,部署目标应该是iOS5.0或更高版本。 Stor...
全文检索对每一个词建立一个索引,指明该词在文章中出现的次数和位置,当用户查询时,检索程序就根据事先建立的索引进行查找,并...
本章节中我们将向大家介绍如何将数据插入到MongoDB的集合中。文档的数据结构和JSON基本一样。所有存储在集合中的数据都是BSON格...
在 SQLite 语句之前,可以使用 "EXPLAIN" 关键字或 "EXPLAIN QUERY PLAN" 短语,用于描述表的细节。 如果省略了 EXPLAIN 关键字...
Redis的Set是string类型的无序集合。集合成员是唯一的,这就意味着集合中不能出现重复的数据。Redis 中 集合是通过哈希表实现的...
Redis SAVE 命令用于创建当前数据库的备份。 语法 redis Save 命令基本语法如下: redis 127.0.0.1:6379 SAVE 实例redis 127.0.0...
oid2name — 解析一个PostgreSQL数据目录中的 OID 和文件结点。 大纲oid2name [option...] 描述 oid2name是一个帮助管理员检查被...
在本章中,我们将研究WordPress中的用户照片。 要在WordPress中添加用户照片,您必须从WordPress插件安装插件用户照片。 它可以...