这可能很简单,但没有任何人在网上提供如何做到这一点的实际例子,我只是无法让它工作。
这是我的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>