javascript - React-Native-Maps:如何动画协调?

标签 javascript google-maps react-native react-redux react-native-maps

我正在使用以下代码但没有成功:

//NativeBase容器内部

        <MapView.Animated
           ref="map"
           style = {styles.map}
           showsUserLocation = {true}
           zoomEnabled = {true}
           showsMyLocationButton = {true}
           showsCompass = {true}
           showScale = {true}
           showsIndoors = {true}
           mapType = {this.state.mapTypes[this.state.mapTypeCode]}
        />

//类的componentDidMount内部

navigator.geolocation.getCurrentPosition(
  (position) => {
    var initialPosition = JSON.stringify(position.coords);
    this.setState({position: initialPosition});

    let tempCoords = {
      latitude: Number(position.coords.latitude),
      longitude: Number(position.coords.longitude)
    }

    this.refs.map.animateToCoordinate(tempCoords, 1);

  }, function (error) { alert(error) },

);

但是出现错误说没有这样的函数 animateToCoordinate。

最佳答案

不幸的是,现在 animateToCoordinate 已被弃用,如果你想这样做,你应该使用 animateCameraanimateToRegion相反。

render() {
  return ( 
    <MapView style = {styles.maps}
      ref = {(mapView) => { _mapView = mapView; }}
      initialRegion = {{
        latitude: 6.8523,
        longitude: 79.8895,
        latitudeDelta: 0.0922,
        longitudeDelta: 0.0421,
      }}
    />
    <TouchableOpacity 
       onPress = {() => _mapView.animateToRegion({
        latitude: LATITUDE,
        longitude: LONGITUDE
      }, 1000)}>
      <Text>Tap</Text>
    </TouchableOpacity>
  )

关于javascript - React-Native-Maps:如何动画协调?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42032015/

相关文章:

javascript - 具有单选按钮功能的复选框

javascript - event.pageX/Y 不适用于 touchmove

javascript - jQuery/正则表达式 : remove all p tags

javascript - leaflet.js 阻止某些事件的传播

javascript - 如何按坐标或标题选择标记?

reactjs - 在 react native + typescript 应用程序上运行 jest 时出错(Jest 遇到意外 token )

react-native - setState() 将 Proxy 对象添加到属性而不是 react native 中的字符串值

javascript - 在生产中调试缓存破坏脚本

java - 从地理点转换为字符串

javascript - 如何在 React Native 中以表格格式显示数据?