Как мне сопоставить маркер Json, чтобы реагировать на нативные карты? - PullRequest
0 голосов
/ 29 сентября 2019

Я застрял на том, как я могу сопоставить JSON, чтобы реагировать на нативные карты.Я пробовал несколько, чтобы отобразить каждую координату, но я получаю "undefined не является функцией рядом с this.state.Markers.map ..." Файл JSON из API:

{
    "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
        }
    ]
}

Мой код, если выПосмотрите на карту, вы увидите метод карты, который я использую: Мой код. Если вы посмотрите на карту, вы увидите метод карты, который я использую:

import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View } from 'react-native';
import MapView, { Marker } from "react-native-maps";

export default class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      region: {
          latitude: 100,
          longitude: 100
      },
      Markers: //get the json
    };
  }


  render() {
    return (
        <View style={styles.container}>
          <MapView
              style={styles.map}
              showsUserLocation={true}
              initialRegion={{
                  latitude: this.state.region.latitude,
                  longitude: this.state.region.longitude,
                  latitudeDelta: 0.03,
                  longitudeDelta: 0.03,
          }}
          >
              {this.state.Markers.map(Markers=> (
                  <Marker
                      coordinate={{ latitude: Markers.member.latitude, longitude: Markers.member.longitude }}
                      title={Markers.member.description}
                  />
              ))}
          </MapView>
        </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  map: {
    ...StyleSheet.absoluteFillObject
  }
});

Я попытался исправить свой код

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...