【发布时间】:2020-07-15 23:54:32
【问题描述】:
我正在实现与自动完成功能相同的 React Native Google Maps 代码,来自此链接:https://medium.com/@Mdmoin07/react-native-google-maps-with-autocomplete-45a5617be2f5
我正在尝试从 MapContainer 类中搜索到位置,但我无法弄清楚。
class MapContainer extends React.Component {
state = {
region: {}
};
componentDidMount() {
this.getInitialState();
}
getInitialState() {
getLocation().then(
(data) => {
this.setState({
region: {
latitude: data.latitude,
longitude: data.longitude,
latitudeDelta: 0.003,
longitudeDelta: 0.003
}
});
}
);
}
getCoordsFromName(loc) {
this.setState({
region: {
latitude: loc.lat,
longitude: loc.lng,
latitudeDelta: 0.003,
longitudeDelta: 0.003
}
});
}
onMapRegionChange(region) {
this.setState({ region });
}
render() {
console.log(this.state.region,"fgg")
// console.log(data.description); what should i write to show data?
return (
<View style={{ flex: 1 }}>
<View style={{ flex: 1 }}>
<MapInput notifyChange={(loc) => this.getCoordsFromName(loc)}
/>
</View>
{
this.state.region['latitude'] ?
<View style={{ flex: 1 }}>
<MyMapView
region={this.state.region}
onRegionChange={(reg) => this.onMapRegionChange(reg)} />
</View> : null}
</View>
);
}
}
export default MapContainer;
如您所见,我可以从该地区(console.log(this.state.region,“fgg”))获取纬度 lng,但我如何获取例如城市名称之类的位置。 我希望我说得足够清楚,我会感谢你的帮助。谢谢!
【问题讨论】:
标签: react-native react-native-maps