react-native-geolocation-amap
v0.1.3
Published
React Native Geolocation Amap
Downloads
1
Readme
react-native-geolocation-amap
Getting started
npm install react-native-geolocation-amap --save
// or
yarn add react-native-geolocation-amap
Usage
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View } from 'react-native';
import GeoLocationAMap, { GeoLocationAMapPurpose } from 'react-native-geolocation-amap';
export default class App extends Component<{}> {
state = {
message: '--'
};
async componentDidMount() {
GeoLocationAMap.init({
android: '944c2ba653f0af996fa7000fd64f377d',
ios: '4dbd01843d2a87e44201ab4b73dc2a3f',
});
GeoLocationAMap.setLocationPurpose(GeoLocationAMapPurpose.SignIn);
GeoLocationAMap.getCurrentPosition((result) => {
this.setState({ message: JSON.stringify(result) });
}, (error) => {
this.setState({ message: error });
});
// const watchId = GeoLocationAMap.watchPosition((result) => {
// this.setState({ message: JSON.stringify(result) });
// }, (error) => {
// this.setState({ message: JSON.stringify(error) });
// });
// console.log(watchId);
// setTimeout(() => {
// GeoLocationAMap.clearWatch(watchId);
// }, 5000);
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>☆Location Info☆</Text>
<Text style={styles.instructions}>{this.state.message}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
marginHorizontal: 10,
},
});