react native 在地图上画一个圆圈

react native draw a circle on the map

这可能非常简单,但是没有任何人在网上提供实际的例子来说明如何做到这一点,我就是无法让它工作。

这是我的 render() 函数,这是我需要做的全部吗? :

render() {
    return (
    <MapContainer>
        <MapView.Circle
            center = {{ latitude: this.state.currentLatitude || 30, longitude: this.state.currentLongitude || 120 }}
            radius = { 1000 }
            strokeColor = "#4F6D7A"
            strokeWidth = { 2 }
        />
        <MapView 
            style = { styles.map }
            region = { this.state.mapRegion }
            showsUserLocation = { true }
            followUserLocation = { true }
            onRegionChangeComplete = { this.onRegionChangeComplete.bind(this) }>
        </MapView>
        <MessageBar />           
    </MapContainer>
    )
}

我试过将 MapView.Circle 标签放在 MapView 标签的上方和下方,但没有任何区别。

有人成功了吗?

这是适用于可能遇到此问题的任何其他人的工作代码:

RADIUS = 500;

class Map extends Component {

state = {
    mapRegion: null,
    currentLatitude: null,
    currentLongitude: null,
    LATLNG: {
        latitude: -35
        longitude: 120
    },
}

render() {
    return (
    <MapContainer>
        <MapView 
            style = { styles.map }
            region = { this.state.mapRegion }
            showsUserLocation = { true }
            followUserLocation = { true }
            onRegionChangeComplete = { this.onRegionChangeComplete.bind(this) }>
        <MapView.Circle
                key = { (this.state.currentLongitude + this.state.currentLongitude).toString() }
                center = { this.state.LATLNG }
                radius = { RADIUS }
                strokeWidth = { 1 }
                strokeColor = { '#1a66ff' }
                fillColor = { 'rgba(230,238,255,0.5)' }
                onRegionChangeComplete = { this.onRegionChangeComplete.bind(this) }
        />
        </MapView>
        <MessageBar />           
    </MapContainer>
    )
}

非常感谢!它为我节省了很多时间。 我在 MapView 中添加组件时也遇到了问题。 这是我想出的。 (只是一个简单的例子,以防万一有人需要它)

<View style={styles.container} >
  <MapView
      style={styles.map}
      initialRegion={{
        latitude: -29.1482491,
        longitude: -51.1559028,
        latitudeDelta: 0.0922,
        longitudeDelta: 0.0421,
      }}>
      <MapView.Circle
        center={{
          latitude: -29.1471337,
          longitude: -51.148951,
        }}
        radius={20}
        strokeWidth={2}
        strokeColor="#3399ff"
        fillColor="#80bfff"
      />
  </MapView>
  <View style={styles.allNonMapThings}>
      <View style={styles.inputContainer}>
        <TextInput
          placeholder=" Type some stuff!"
          style={ styles.input }
          keyboardType="numeric"
        />
      </View>

      <View style={styles.button} >
        <TouchableOpacity > 
          <Text style = {styles.buttonText} >
            Search
          </Text>
        </TouchableOpacity>
      </View>
    </View>
  </View>