繁体   English   中英

如何在 react-native-maps 中获取 GPS 位置

[英]How to get GPS location in react-native-maps

我的 react-native 应用程序使用react-native-maps来显示谷歌地图和标记。 样式View用作在设备屏幕上具有固定位置的位置标记。

问题:我们如何获得标记的 GPS 坐标(纬度/经度),例如<View style={styles.marker}>组件的左下角?

<MapView
    ref='map'
    initialRegion={{
        latitude: LATITUDE,
        longitude: LONGITUDE,
        latitudeDelta: LATITUDE_DELTA,
        longitudeDelta: LONGITUDE_DELTA,
    }}
    showsUserLocation={true}
></MapView>

<View style={styles.markerContainer}>
    <View style={styles.marker}>
    </View>
</View>

风格

var deviceHeight = Dimensions.get('window').height;
StyleSheet.create({
    markerContainer: {
        bottom: deviceHeight/2.2,
        position: 'absolute',
        left: 0,
        right: 0,
    },
})

我的react-native应用程序正在使用react-native-maps显示Google Maps和标记。 样式化的View用作在设备屏幕上具有固定位置的位置标记。

问题:如何获取标记的GPS坐标(纬度/经度),例如<View style={styles.marker}>组件的<View style={styles.marker}>

<MapView
    ref='map'
    initialRegion={{
        latitude: LATITUDE,
        longitude: LONGITUDE,
        latitudeDelta: LATITUDE_DELTA,
        longitudeDelta: LONGITUDE_DELTA,
    }}
    showsUserLocation={true}
></MapView>

<View style={styles.markerContainer}>
    <View style={styles.marker}>
    </View>
</View>

样式

var deviceHeight = Dimensions.get('window').height;
StyleSheet.create({
    markerContainer: {
        bottom: deviceHeight/2.2,
        position: 'absolute',
        left: 0,
        right: 0,
    },
})
<MapView
    ref='map'
    initialRegion={{
        latitude: LATITUDE,
        longitude: LONGITUDE,
        latitudeDelta: LATITUDE_DELTA,
        longitudeDelta: LONGITUDE_DELTA,
    }}
    showsUserLocation={true}


**onUserLocationChange={(e)=>console.log(e.nativeEvent.coordinate)}**
></MapView>

<View style={styles.markerContainer}>
    <View style={styles.marker}>
    </View>
</View>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM