如何改变标记在本机中的位置?

问题描述 投票:0回答:1

您好,我想在地图上添加可拖动的标记,“基于地图视图更改标记的位置”因此,我使用react-native-maps,

当用户滑动地图并更改其位置时,标记会带有下摆,因此在我的代码中,我将其记录在控制台中,但看不到日志中的任何内容,或者它不是用这种方式制成的!如何使其在地图上可拖动?

这是我想要实现的map

这是我的代码

import React, {Component} from 'react';
import {StyleSheet, View} from 'react-native';
import MapView, {Marker} from 'react-native-maps';

// create a component
class App extends Component {
  state = {
    latlng: {
      latitude: 35.1790507,
      longitude: -6.1389008,
    },
  };
  render() {
    return (
      <View style={styles.container}>
        <MapView
          style={styles.map}
          region={{
            latitude: 35.1790507,
            longitude: -6.1389008,
            latitudeDelta: 0.015,
            longitudeDelta: 0.0121,
          }}>
          <Marker
            draggable
            coordinate={this.state.latlng}
            title="Home"
            onDragEnd={e => {
              console.log('dragEnd', e.nativeEvent.coordinate);
            }}
          />
        </MapView>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    ...StyleSheet.absoluteFillObject,
    // height: 400,
    // width: 400,
    justifyContent: 'flex-end',
    alignItems: 'center',
  },
  map: {
    ...StyleSheet.absoluteFillObject,
  },
});

//make this component available to the app
export default App;
reactjs react-native react-native-android react-native-maps
1个回答
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.