获取 onLongPress 事件发生位置的坐标 - react-native-maps
Get coordinates of where onLongPress event took place - react-native-maps
我正在尝试获取 onLongPress 事件发生位置的纬度和经度坐标。我有偶数设置,但不知道坐标存储在事件中的位置。有人有这方面的经验吗?
<MapView
initialRegion={{
latitude: props.location.coords.latitude,
longitude: props.location.coords.longitude,
latitudeDelta: 0.04,
longitudeDelta: 0.05,
}}
onLongPress={(e) => {
console.log(e);
}}
showsMyLocationButton={true}
showsUserLocation={true}
style={styles.map}
>
{markers.map((marker, index) => (
<Marker
key={index}
coordinate={marker.latlng}
title={marker.title}
description={marker.description}
onPress={() => navigation.navigate("Marker", { data: marker })}
></Marker>
))}
</MapView>
console.log(e)
打印出一个巨大的物体,但我在该物体的任何地方都看不到坐标。
它隐藏在e.nativeEvent
中。考虑以下代码片段以访问 coordinates
.
<MapView
...
onLongPress={(e) => {
console.log(e.nativeEvent)
}}
...
>
...
</MapView>
nativeEvent
包含以下对象。
{
target: 127,
coordinate: {
latitude: 47.66491318510563,
longitude: 4.238049164414406
},
position: {
y: 489.9999084472656,
x: 263.99993896484375
}
}
我正在尝试获取 onLongPress 事件发生位置的纬度和经度坐标。我有偶数设置,但不知道坐标存储在事件中的位置。有人有这方面的经验吗?
<MapView
initialRegion={{
latitude: props.location.coords.latitude,
longitude: props.location.coords.longitude,
latitudeDelta: 0.04,
longitudeDelta: 0.05,
}}
onLongPress={(e) => {
console.log(e);
}}
showsMyLocationButton={true}
showsUserLocation={true}
style={styles.map}
>
{markers.map((marker, index) => (
<Marker
key={index}
coordinate={marker.latlng}
title={marker.title}
description={marker.description}
onPress={() => navigation.navigate("Marker", { data: marker })}
></Marker>
))}
</MapView>
console.log(e)
打印出一个巨大的物体,但我在该物体的任何地方都看不到坐标。
它隐藏在e.nativeEvent
中。考虑以下代码片段以访问 coordinates
.
<MapView
...
onLongPress={(e) => {
console.log(e.nativeEvent)
}}
...
>
...
</MapView>
nativeEvent
包含以下对象。
{
target: 127,
coordinate: {
latitude: 47.66491318510563,
longitude: 4.238049164414406
},
position: {
y: 489.9999084472656,
x: 263.99993896484375
}
}