繁体   English   中英

如何使用 react-native-maps 启用倾斜?

[英]How to enable tilt with react-native-maps?

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

在此处输入图片说明

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

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

更多信息,请访问此GitHub 线程

这是一个对我有用的代码片段

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 月)

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM