缩放或收缩时,如何使MapView标记停留在给定坐标处?

时间:2019-07-19 05:46:48

标签: google-maps react-native

我目前正在使用React Native上的MapView.Marker,现在我可以通过代码设置标记位置,在我放大/缩小或像这样放大屏幕之前,一切似乎都可以正常工作

enter image description here

enter image description here

如上图所示,标记已略微移出其位置

我用来固定标记的代码是

    onRegionChange = region => {
        this.setState({
          region
        })
    }

    setMarkerRegion = () => {
        const { region } = this.state;
        this.setState({
          markerRegion: region,
          locationMarked: true,
        });
    }
    <MapView
          ref={m => { this.map = m }}
          style={{ flex: 10 }}
          initialRegion={region}
          onRegionChangeComplete={this.onRegionChange}
          provider={PROVIDER_GOOGLE}
          customMapStyle={customStyles}>
      <Marker
        coordinate={{
             latitude: markerRegion.latitude,
             longitude: markerRegion.longitude
        }}
        style={{ alignSelf: 'center' }}
        title={"This is a title <3"}
        description={searchLocation}
      />
    </MapView>
<TouchableOpacity style={[styles.markerFixed]} onPress={this.setMarkerRegion}>
  <Icon name={'map-marker'} color={'white'} type='font-awesome' containerStyle={styles.marker}></Icon>
</TouchableOpacity>

我正在尝试在SO上进行搜索,但是在本机android上只有一个示例,在这种情况下没有帮助,任何想法都将不胜感激。

0 个答案:

没有答案