import React, { Component } from "react";
import {
Platform,
StyleSheet,
Text,
View,
Alert,
TouchableOpacity
} from "react-native";
export default class App extends Component {
state = {
location: null
};
findCoordinates = () => {
navigator.geolocation.getCurrentPosition(
position => {
const location = JSON.stringify(position);
this.setState({ location });
},
error => alert(error.message),
{ enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
);
alert("SKIPPED");
};
render() {
return (
<View style={styles.container}>
<TouchableOpacity onPress={this.findCoordinates}>
<Text style={styles.welcome}>Find My Coords?</Text>
<Text>Location: {this.state.location}</Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
... some style ...
});
由于我使用的是Android仿真器,所以在
AndroidManifest.xml
文件位于
android\app\src\main
application
标签:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
getCurrentPosition
函数似乎只是被跳过了。状态未更新,未显示任何错误,并显示警报“跳过”。
这就是我在“跳过”警报解除后在屏幕上看到的情况: