Reactjs 反应本机映射框获取单击位置
我成功地将@react native mapbox gl/maps添加到我的项目中。 现在,我不需要用户的当前位置,但我只需要获得用户在地图上单击的位置的坐标(lat&lng)。我什么都试过了,但都没用! 我的代码:Reactjs 反应本机映射框获取单击位置,reactjs,react-native,google-maps,mapbox,openstreetmap,Reactjs,React Native,Google Maps,Mapbox,Openstreetmap,我成功地将@react native mapbox gl/maps添加到我的项目中。 现在,我不需要用户的当前位置,但我只需要获得用户在地图上单击的位置的坐标(lat&lng)。我什么都试过了,但都没用! 我的代码: 从'@react native mapbox gl/maps'导入MapboxGL,{MapView,UserLocation}; MapboxGL.setAccessToken( ‘MyAccessToken’,); 导出默认类。。。。{ getLastLocation(位置){
从'@react native mapbox gl/maps'导入MapboxGL,{MapView,UserLocation};
MapboxGL.setAccessToken(
‘MyAccessToken’,);
导出默认类。。。。{
getLastLocation(位置){
ToastMaker(位置“短”)
}
render(){
返回(
使用属性
console.log('Coords:',feature.geometry.coordinates)}
>
...
有关完整示例,请参见使用属性
console.log('Coords:',feature.geometry.coordinates)}
>
...
参见完整示例,人们说消防员是真正的英雄,而我们在Stackoverflow上有一个:人们说消防员是真正的英雄,而我们在Stackoverflow上有一个:D
import MapboxGL, {MapView, UserLocation} from '@react-native-mapbox-gl/maps';
MapboxGL.setAccessToken(
'MyAccessToken', );
export default class .... .... {
getLastLocation(location) {
ToastMaker(location, 'short')
}
render() {
return (
<View style={{flex: 1}}>
<View style={{height: '100%',
width: '100%',
backgroundColor: 'blue'}}>
<MapView style={{ flex: 1}}
//These Don't Work!
//onUserLocationUpdate={(property) => this.getLastLocation(property)}
//onLongPress={(property) => this.getLastLocation(property[0].coordinates)}
//onLongPress={(property) => this.getLastLocation(property.geometry) }
//onLongPress={(property) => ToastMaker(property.properties.screenPointY,'short') }
>
<MapboxGL.PointAnnotation
draggable={true}
id={'1'}
selected={true}
coordinate={this.state.coordinates}
/>
</MapView>
</View>
</View>
)
}
}