1
我是新来的反应。我期望使用Cordova插件从Web-App构建移动应用程序。 所以在这种情况下,我想获得应用程序的位置。我正在尝试使用react-native地理位置。React-native Geolocation
我跟着facebook的教程here。但是当我尝试它时,它没有显示我的位置。取而代之的是从未知的到{}的位置变化值。
我在这里可能会出现很少的错误。
- 我使用代理
- 测试这不是在Android或任何其他本机设备的浏览器。
- Facebook的链接说,这是反应母语,但我的项目是由创建反应的应用程序内,我认为还没有反应过来,原生
如果这些是不是这个错误的原因,请帮助创建。
我的代码,
import React,{Component} from 'react';
class GeoLocation extends React.Component {
\t state = { initialPosition: 'unknown',
\t \t \t lastPosition: 'unknown', };
\t watchID: ?number = null;
\t componentDidMount() {
\t \t if (navigator.geolocation) {
\t \t \t navigator.geolocation.getCurrentPosition((position) => {
\t \t \t \t var initialPosition = JSON.stringify(position);
\t \t \t \t this.setState({initialPosition});
\t \t \t },
\t \t \t (error) => alert(JSON.stringify(error)), {
\t \t \t \t enableHighAccuracy: true, timeout: 20000, maximumAge: 1000
\t \t \t });
\t \t \t
\t \t \t this.watchID = navigator.geolocation.watchPosition((position) => {
\t \t \t \t var lastPosition = JSON.stringify(position);
\t \t \t this.setState({lastPosition});
\t \t });
\t \t }
\t \t }
\t componentWillUnmount() {
\t navigator.geolocation.clearWatch(this.watchID);
\t }
\t render() {
\t \t \t return (
\t \t \t \t <div className="main">
\t \t \t \t \t <h1> Initial position: {this.state.initialPosition} </h1>
\t \t \t \t \t <h1> Current position: {this.state.lastPosition} </h1>
\t \t \t </div>
\t \t \t);
\t \t }
}
export default GeoLocation;
谢谢!它似乎很酷,但我正在为这个学期项目做这个。所以买不起这样的服务。非常感谢。 :) – HelpingHand
顺便说一下,侧边导航栏中的链接似乎在DOCS页面中断了!我正在阅读文档时遇到一些麻烦! – HelpingHand
@HelpingHand - 该服务可以免费进行跟踪,在“沙盒”/测试模式下,您可以对最多20个用户执行无限次的操作。 另外,哪些链接? – Jerdog