javascript - 使用 forEach 显示来自 React Native Maps 的标记
问题描述
我的状态中有这个数组:
coinCoordinatesArray: [
{
latitude: 37.78825,
longitude: -122.4324},
{
latitude: 38.78825,
longitude: -120.4324},
{
latitude: 31.78825,
longitude: -80.4324},
{
latitude: 55.78825,
longitude: -95.4324}
我正在尝试使用该州的坐标来渲染标记:
{this.state.coinCoordinatesArray.forEach((coordinate) => {
return (<MapView.Marker
onPress={() => alert('fire')}
icon={require('./assets/coin_small.png')}
coordinate={coordinate}
/>)
})}
然而,标记根本没有呈现,但我也没有得到任何错误。
解决方案
您正在执行 a forEach()
,它只生成元素,您可能想要执行 a map()
,因此您的项目被累积到一个数组中并被渲染。
推荐阅读
- ms-word - MS Office Word 如何添加客户功能区并同时出现在其他计算机上?
- powershell - 如何使用 Get-ChildItem 返回没有扩展名的文件?
- bash - 通过 bash 过滤 json - 不区分大小写
- react-native - 为多个应用程序使用单个 expo 代码库
- swift - 我想禁用“发布”按钮并在选择图像后再次启用它?
- c# - Unity - 像声波一样运行循环而不会摔倒
- ios - AVFoundation 相机预览层与水平方向不匹配(Swift 4)
- mysql - 想要根据(贷方金额 > 100k)和借方金额(>=90% 贷方金额和 <=105% 贷方金额)查找交易
- php - Laravel 记录到 Slack 工作簿会导致“Curl 错误(代码 3):
畸形” - mysql - 如何根据tableB记录行在tableA中插入多条记录?