如何在信息窗口中显示结果[0].formatted_address
How to display results[0].formatted_address in InfoWindow
我现在正在用 React 制作 google 地图,但 placeId 的显示结果有问题。我有这个代码:
<Marker
{...marker}
key={i}
position={marker.location}
title={marker.title}
icon={'icons/' + marker.type + '.png'}
onClick={() => {
props.toggleLocationsActive(i);
}}
//animation={DROP}
>
{i === props.activeKey && (
geocodeByPlaceId(marker.place_id)
.then(results => {
const address = results[0].formatted_address;
console.log(address);
})
.catch(error => console.error(error)),
<InfoWindow onCloseClick={props.onToggleOpen}>
<div>{ marker.title }</div>
</InfoWindow>)}
</Marker>
我想在 InfoWindow 中显示从这个 placeId 获取的地址 - 显示 {marker.title}。而且我不知道该怎么做...这是 GitHub 存储库上该项目的 link:https://github.com/hajczek/Neighborhood---Warsaw-Cultural-Map 也许你们中的一些人知道,如何解决这个问题.. . 感谢您的任何回答:)
我通过这种方式解决了这个问题:
document.getElementById('address').textContent = address;
我把这段代码放到 'then' 的一部分:
.then(results => {
const address = results[0].formatted_address;
console.log(address);
document.getElementById('address').textContent = address;
})
我现在正在用 React 制作 google 地图,但 placeId 的显示结果有问题。我有这个代码:
<Marker
{...marker}
key={i}
position={marker.location}
title={marker.title}
icon={'icons/' + marker.type + '.png'}
onClick={() => {
props.toggleLocationsActive(i);
}}
//animation={DROP}
>
{i === props.activeKey && (
geocodeByPlaceId(marker.place_id)
.then(results => {
const address = results[0].formatted_address;
console.log(address);
})
.catch(error => console.error(error)),
<InfoWindow onCloseClick={props.onToggleOpen}>
<div>{ marker.title }</div>
</InfoWindow>)}
</Marker>
我想在 InfoWindow 中显示从这个 placeId 获取的地址 - 显示 {marker.title}。而且我不知道该怎么做...这是 GitHub 存储库上该项目的 link:https://github.com/hajczek/Neighborhood---Warsaw-Cultural-Map 也许你们中的一些人知道,如何解决这个问题.. . 感谢您的任何回答:)
我通过这种方式解决了这个问题:
document.getElementById('address').textContent = address;
我把这段代码放到 'then' 的一部分:
.then(results => {
const address = results[0].formatted_address;
console.log(address);
document.getElementById('address').textContent = address;
})