如何在本机标记中适应特定标记的缩放?

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

您可以在此处找到以下代码:

https://snack.expo.io/@matheus_cbrl/react-native-maps-autocomplete

在这种情况下,当应用初始化时,将销钉设置在当前位置,但是在同一张地图中,我还有其他标记,当我尝试选择其他标记使其再次适合当前位置时,如何解决此问题?我需要选择任何一个标记,当我找到某个地方时,它会设置一个新的标记,并通过缩放选中的标记来设置一个新的视图...有人可以帮助我???

<View style={styles.container}>
    <StatusBar hidden />
    <MapView
      onPress={this.handleMapPress}
      style={StyleSheet.absoluteFill}
      ref={map => (this.mapView = map)}
      rotateEnabled={true}
      scrollEnabled={true}
      showsMyLocationButton={true}
      followsUserLocation={true}
      showsUserLocation={true}
      zoomEnabled={true}
      showsPointsOfInterest={true}
      showBuildings={false}
      //region={this.props.region}
      initialRegion={region}
      provider="google">
      {!!location && (
        <MapView.Marker
          coordinate={location}
          onPress={this.handleMarkerPress}>
          <Image
            source={isAddressVisible ? placholder2 : placholder}
            style={styles.icon}
          />
        </MapView.Marker>
      )}
      {this.state.coordinates.map(
        (coordinates, index, title, description, location) => (
          <MapView.Marker
            onPress={this.handleMapPress}
            ref={mark => (coordinates.mark = mark)}
            key={`coordinate_${index}`}
            title={coordinates.title}
            description={coordinates.description}
            coordinate={{
              latitude: coordinates.latitude,
              longitude: coordinates.longitude,
            }}>
            <Image
              source={isAddressVisible ? placholder2 : placholder}
              style={styles.icon}
            />
          </MapView.Marker>
        )
      )}
      <MapView.Marker coordinate={this.props.region} >
          <Image
            source={ markerImage}
            style={styles.icon}
          />
      </MapView.Marker>
    </MapView>
google-maps react-native google-maps-markers
1个回答
0
投票

我已经解决了这个问题,这是您阅读的点心...

这是下面的简单代码:

  pickLocationHandler = event => {
const coords = event.nativeEvent.coordinate;

this.map.animateToRegion({
  ...this.state.focusedlocation,
  latitude: coords.latitude,
  longitude: coords.longitude,
});

this.setState(prevState => {
  return {
    focusedlocation: {
      ...prevState.focusedlocation,

      latitude: coords.latitude,

      longitude: coords.longitude,
    },

    locationChosen: true,
  };
});
};

getLocationHandler = () => {
navigator.geolocation.getCurrentPosition(
  pos => {
    const coordsEvent = {
      nativeEvent: {
        coordinate: {
          latitude: pos.coords.latitude,

          longitude: pos.coords.longitude,
        },
      },
    };

    this.pickLocationHandler(coordsEvent);
  },

  err => {
    console.log(err);

    alert(
      'Ocorreu um erro ao carregar sua localização, por favor ligue o GPS!'
    );
  }
 );
};

并且我在创建的按钮上调用此函数:

        <TouchableOpacity
     onPress={this.getLocationHandler}
      style={styles.fab2}>
            <Image
              source={require('../assets/gps.png')}
              style={{
                width: 35,
                height: 35,
                margin: 10,
                tintColor: '#FF3D00',
              }}
            />
    </TouchableOpacity>

这里是完整代码的链接:

https://snack.expo.io/@matheus_cbrl/react-native-maps-autocomplete

如果这回答了您可能的问题,请喜欢它!! :)

© www.soinside.com 2019 - 2024. All rights reserved.