React Native Google 具有自动完成功能的地图获取位置
React Native Google Maps with Autocomplete get the location
我正在实现与 React Native Google 具有自动完成功能的地图完全相同的代码,来自此 link:https://medium.com/@Mdmoin07/react-native-google-maps-with-autocomplete-45a5617be2f5
我正在尝试从 class 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")) 但我如何才能获取城市名称等位置.
我希望我说得足够清楚,我会很感激你helping.thanks!
您的代码看起来没问题。我遇到了类似的问题,就我而言,这是 Google 开发人员控制台上的配置不正确。
要获取姓名和地址,我需要在 Google developer console
上对我的项目启用 Places Api
,然后代码开始运行。
我正在实现与 React Native Google 具有自动完成功能的地图完全相同的代码,来自此 link:https://medium.com/@Mdmoin07/react-native-google-maps-with-autocomplete-45a5617be2f5
我正在尝试从 class 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")) 但我如何才能获取城市名称等位置. 我希望我说得足够清楚,我会很感激你helping.thanks!
您的代码看起来没问题。我遇到了类似的问题,就我而言,这是 Google 开发人员控制台上的配置不正确。
要获取姓名和地址,我需要在 Google developer console
上对我的项目启用 Places Api
,然后代码开始运行。