gpt4 book ai didi

android - 一些自定义标记不会出现在 Android react-native-maps 上

转载 作者:行者123 更新时间:2023-11-29 00:55:08 25 4
gpt4 key购买 nike

在我们的应用程序中,我们在他登录时获取用户位置(点击登录 -> 获取位置 -> 在 redux 中保存位置 -> 导航到主屏幕)。当 Home 组件挂载时,它应该使用该位置从用户周围的区域获取数据。

在 iOS 中,所有标记都正确呈现,但在 Android 设备中,并非所有标记都被呈现,只有其中一些(奇怪的是,所有标记都是 image1 或 image2)。

只有当我们再次调用 getDataFromRegion 函数时,所有标记才能正确呈现。知道我们做错了什么吗?

class Login extends Component {

handleLogin = (u, p) => {

getLocation(location => {

let region = {
latitude: location.coords.latitude,
longitude: location.coords.longitude,
latitudeDelta: 0.06,
longitudeDelta: 0.06
}

/* save location in redux */
this.props.setLocation(region)
login(u, p).then(() => _gotoHome())
})
}
}

class Home extends Component {

componentWillMount() {

if(this.props.location !== undefined) {

initialRegion = {
latitude: this.props.location.latitude,
longitude: this.props.location.longitude,
latitudeDelta: 0.06,
longitudeDelta: 0.06
}
}
}

componentDidMount() {
/* set data in redux */
this.getDataFromRegion(initialRegion)
}

render() {
this.props.data.map((data, index) => data.visible ? <CustomMarker key={index} data={data}/> : null)
}
}


class CustomMarker extends Component {
render() {
const {data} = this.props
const coords = { latitude: data.lat, longitude: data.lng }

return (

<MapView.Marker
coordinate={coords}
onLoad={() => this.forceUpdate()}
tracksViewChanges={Platform.OS === 'android' ? false : true}
>
<Image
onLoad={() => this.forceUpdate()}
source={data.a === '0' ? image1 : image2}
style={{width: 60, height: 60}}
/>
</MapView.Marker>
)
}
}

最佳答案

似乎删除了 Image 组件并使用 MapView.Marker 属性 image 使其正常工作。此外,在 MapView 中渲染一个带有 opacity: 0 的虚拟 MapView.Marker 解决了在第一次渲染调用时出现默认标记的问题。

关于android - 一些自定义标记不会出现在 Android react-native-maps 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55364895/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com