我被困在如何映射JSON以响应本地映射的问题上。我尝试了一些是映射每个坐标API的JSON文件:
{
"request_time": "2019-09-28T22:13:25+01:00",
"source": "NaPTAN",
"acknowledgements": "Contains DfT NaPTAN bus stops data",
"member": [
{
"type": "bus_stop",
"name": "Western Avenue - SW-bound",
"description": "Buckingham",
"latitude": 52.00437,
"longitude": -0.98989,
"accuracy": 20,
"atcocode": "040000004581",
"distance": 846.0
},
{
"type": "bus_stop",
"name": "Overn Avenue - NE-bound",
"description": "Buckingham",
"latitude": 52.00378,
"longitude": -0.98884,
"accuracy": 20,
"atcocode": "040000002388",
"distance": 872.0
}
]
}
在此MapView部分中,您将看到我正在使用的地图方法,由于某些原因标记未显示。我收到一个TypeError:this.state.markers.map不是一个函数:
<MapView
style={styles.map}
showsUserLocation={true}
initialRegion={{
latitude: this.state.latitude,
longitude: this.state.longitude,
latitudeDelta: 0.0462,
longitudeDelta: 0.0261,
}}
>
{this.state.markers.map(marker => (
<Marker
coordinate={{ latitude: marker.member.latitude, longitude: marker.member.longitude}}
/>
))}
</MapView>
);
}
}
这里是展览代码:https://snack.expo.io/S1rcu7guB
[this.state.markers.map is not a function
表示您试图在非数组变量(在这种情况下为map
)上使用this.state.markers
函数。