0
我需要更新从实际位置的经度和纬度(当前位置不是假的位置,我设置)反应原生(IOS)。我需要更新和打印值的经度和纬度
,我设置的值是假的位置 纬度:14.0208, 经度:100.525
我试着在我的设备上发布。 GPS已
,但我不知道如何从实际位置(实时更新)
谢谢打印。
这是我的代码:
import React, { Component, PropTypes } from 'react';
import {
StyleSheet,
View,
Text,
Image,
Dimensions,
TouchableOpacity,
MapView
} from 'react-native';
var {height, width} = Dimensions.get('window');
import api from './api';
import Profile from './Profile';
import ScrollableTabView, {DefaultTabBar, ScrollableTabBar } from 'react-native-scrollable-tab-view';
import Info from './Info';
// import motion from './motion';
export default class Route extends Component {
constructor(props){
super(props);
this.state = {
region: {
latitude: 14.0208,
longitude: 100.5250,
}
};
}
render() {
return (
<View style={styles.container}>
<ScrollableTabView
style={{marginTop: 20, }}
initialPage={2}
renderTabBar={() => <ScrollableTabBar />}
>
<Text tabLabel='Profile'></Text>
<Text tabLabel='Route'></Text>
<Text tabLabel='Information'></Text>
</ScrollableTabView>
<TouchableOpacity tabLabel='Profile' onPress={() => this.tabView.Profile(2)}>
</TouchableOpacity>
<MapView style={styles.map}
mapType="standard"
showsUserLocation={true}
followsUserLocation={true}
showsCompass={false}
showsPointOfInterest={false}
region={this.state.region}
onRegionChange={this.onRegionChange}
>
</MapView>
<View style={styles.container}>
<Text>
Latitude: {this.state.region.latitude}{'\n'}
Longitude: {this.state.region.longitude}{'\n'}
</Text>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'white'
},
image: {
width: 200,
height: 180,
},
text: {
color: 'white',
fontWeight: 'bold',
backgroundColor: 'transparent',
marginTop: 20,
},
map: {
//top: -150,
width: 700,
height: 400
}
});
我能解决这个问题,但是当我重新加载它只是在模拟器(延迟)慢如何解决这个问题 我只是加上我的代码,并获得延迟 this.onRegionChange = this.onRegionChange。绑定(本); } onRegionChange(region){ \t this.setState({region}); } –