【问题标题】:How to enable tilt with react-native-maps?如何使用 react-native-maps 启用倾斜?
【发布时间】:2018-05-28 17:57:46
【问题描述】:

我正在使用 react-native-maps。我的问题很简短。那么如何将初始相机水平位置设置为图像静止?

【问题讨论】:

    标签: reactjs react-native react-native-maps


    【解决方案1】:

    要倾斜地图并从另一个角度查看,请使用animateToViewingAngle

    我知道 iOS 本身就支持它,所以你应该在 iOS 上默认这种行为。但是,我不确定Android。

    更多信息,请访问GitHub Thread

    【讨论】:

    • 嗨 Rex,我用过那个,但它只用于纬度和长期位置,我错了吗? ` this.map.animateToRegion({ latitude: location.latitude, longitude: location.longitude, latitudeDelta: 0.0029397161733585335, longitudeDelta: 0.002845874547958374, }); `
    • @UğurErdal 您应该能够使用此道具定义初始位置。 this.map.animateToRegion 用于渲染下一个带有一点动画的位置。你能详细说明你的问题吗?
    • 我按你说的试过了,但它不起作用。我的问题是你可以用两根手指在屏幕上滚动。例如,当时的建筑物看起来像 3d。所以我想这样做。地图打开时。它应该像 3d 一样打开默认值(我不知道 3d 事物的名称。如图所示)@rex-low
    • 道具名称也是pitchEnabled btw。
    • 我发现它 man animateToViewingAngle() 它的工作是我想要的。谢谢你的工作
    【解决方案2】:

    这是一个适合我的代码 sn-p

    import React from 'react';
    import MapView from 'react-native-maps';
    import { StyleSheet, Text, View, Dimensions } from 'react-native';
    
    export default class App extends React.Component {
      render() {
        return (
          <View style={styles.container}>
            <MapView 
              showsBuildings
              ref={ref => { this.map = ref }}
              onLayout={() => {
                this.map.animateToBearing(125);
                this.map.animateToViewingAngle(45);
              }}
              initialRegion={{
                latitude: 41.8781,
                longitude: -87.6298,
                latitudeDelta: 1 / 300,
                longitudeDelta: 2 / 300
              }}
              style={styles.mapStyle}
            />
          </View>
        );
      }
    }
    
    const styles = StyleSheet.create({
      container: {
        flex: 1,
        backgroundColor: '#fff',
        alignItems: 'center',
        justifyContent: 'center',
      },
      mapStyle: {
        width: Dimensions.get('window').width,
        height: Dimensions.get('window').height,
      },
    });
    

    小吃演示 https://snack.expo.io/Sym1DTm0r(截至 2019 年 12 月)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-27
      • 1970-01-01
      • 2016-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多