我想同時顯示通過MQTT接收的所有坐標,但目前代碼僅顯示最新的緯度和經度對。有人有什么建議嗎?constructor(props) { super(props); this.state = { coordinates: [ {latitude: 0, longitude: 0} ] };};componentDidMount() { client.on('connect', () => { client.subscribe('topic'); }); client.on('message', (_topic, message) => { var parsedBody = JSON.parse(message.toString()); var mqttLat = parsedBody["latitude"]; var mqttLong = parsedBody["longitude"]; this.setState({ coordinates: [ {latitude: mqttLat, longitude: mqttLong} ] }); });};<View> <MapView> {this.state.coordinates.map((marker, i) => ( <Marker key = {i} coordinate = {{ latitude: marker.latitude, longitude: marker.longitude }}> </Marker> ))} </MapView></View>
如何在 React Native 中顯示所有接收到的坐標?
慕的地6264312
2022-08-18 10:39:19