【发布时间】:2017-04-07 13:12:28
【问题描述】:
我有一个问题,但我不知道它是否与此有关。
当我从 Android Studio 在 Android Emulator 上运行我的地图时,我收到了这个警告,我在 Palo alto 的 Google plex 上进行地理定位,而不是在我的实际地理位置上。是不是因为我用了模拟器?
如果你想检查,这是我的代码:
地图.js
import React, { Component } from 'react';
import Geolocation from '../geolocation/Geolocation';
import Shops from '../shops/Shop';
import {
Text,
View
} from 'react-native';
import MapView from 'react-native-maps';
import styles from './Style';
class Map extends Geolocation {
render() {
return (
<View>
<MapView style={styles.map}
region={{
latitude: this.state.position.coords.latitude,
latitudeDelta: 0.001,
longitude: this.state.position.coords.longitude,
longitudeDelta: 0.001
}} />
<Shops />
</View>
);
}
}
export default Map;
地理位置.js
import React, { Component } from 'react';
import styles from './Style';
class Geolocation extends Component {
constructor(props) {
super(props);
this.state = {
position : {
coords: {}
}
}
}
componentDidMount() {
navigator.geolocation.getCurrentPosition(
(position) => {
this.setState({position});
},
(error) => alert(error.message),
{enableHighAccuracy: true, timeout: 20000}
);
navigator.geolocation.watchPosition((position) => {
this.setState({position});
});
}
}
export default Geolocation;
如果您有任何想法,感谢您的回答,我对这个问题有点迷茫。
【问题讨论】:
标签: javascript reactjs react-native react-native-android