【发布时间】:2021-10-06 05:01:05
【问题描述】:
我正在使用 react-native-maps。我有一个项目列表,我将其作为标记显示在地图中。 如何检测标记是否在用户在地图中搜索的视图中。 我尝试使用 react-native-component-inview 包,但它不起作用。 这是我完整 MapView 的代码
<MapView
ref={mapRef}
provider="google"
initialRegion={tripdata.pickup ? initialRegion : qatarRegion}
onRegionChange={onRegionChange}
onRegionChangeComplete={onRegionChangeComplete}
>
{mapAds
? mapAds.map((item, index) => {
return (
<Marker
onPress={() => mapEngagement(item.id)}
coordinate={{
latitude: item.lat ? item.lat : 0.0,
longitude: item.lng ? item.lng : 0.0,
}}
key={index}
>
<TouchableOpacity
style={{
width: 50,
height: 50,
backgroundColor: colors.GREY.YELLOW,
borderRadius: 100,
justifyContent: "center",
alignItems: "center",
}}
>
<Image
source={{
uri: item.logo
? item.logo
: "https://firebasestorage.googleapis.com/v0/b/faroutdrive001.appspot.com/o/corporations%2F-McAZ_l4YQ4X4Hg71dTF%2Flogo?alt=media&token=de3aff61-0deb-4cea-a3f0-0e0b491146b1",
}}
style={{
height: 47,
width: 47,
zIndex: 2,
borderRadius: 100,
}}
/>
{/* <Text>{visible}</Text> */}
</TouchableOpacity>
<Callout tooltip>
<View style={{ padding: 3 }}>
<TouchableOpacity
style={{
backgroundColor: colors.GREY.YELLOW,
justifyContent: "space-evenly",
alignItems: "center",
minWidth: 120,
maxWidth: 150,
minHeight: 50,
borderRadius: 10,
}}
>
<Text style={{ color: colors.WHITE }}>
{item.ad_name ? item.ad_name : "Advertise Here"}
</Text>
<Text style={{ color: colors.WHITE, fontSize: 12 }}>
{item.ad_description ? item.ad_description : ""}
</Text>
</TouchableOpacity>
</View>
</Callout>
</Marker>
);
})
: null}
</MapView>
【问题讨论】:
-
请为实际地图添加您的代码,而不仅仅是标记,所以我们都在同一个页面上。我将添加一个暂定答案供您参考。
-
@Atmas 添加了整个 MapView 代码
-
好的。那里没有什么太出乎意料的地方,但想确定一下。下面的答案应该会让您顺利进行,但这并不完全是一种直接响应。我在 JS 代码中没有这样的示例(我使用 Java 来满足我的画中画需要),否则我会给你一个。如果我能提供进一步的帮助,我会倾听。
标签: javascript android ios react-native react-native-maps