Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 反应本机映射框获取单击位置_Reactjs_React Native_Google Maps_Mapbox_Openstreetmap - Fatal编程技术网

Reactjs 反应本机映射框获取单击位置

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添加到我的项目中。 现在,我不需要用户的当前位置,但我只需要获得用户在地图上单击的位置的坐标(lat&lng)。我什么都试过了,但都没用! 我的代码:

从'@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>
        )
    }

}