旋转后居中的地图

时间:2018-10-03 11:39:32

标签: react-native react-native-android react-native-maps

当我旋转地图并更新区域时,它会自动居中

import React, { Component } from 'react';
import {
    StyleSheet,
    Dimensions,
} from 'react-native';
import MapView from "react-native-maps";

const {width, height} = Dimensions.get('window');
const ASPECT_RATIO = width / height;
const LATITUDE_DELTA = 0.5;
const LONGITUDE_DELTA = LATITUDE_DELTA * ASPECT_RATIO;


type Props = {};
export default class App extends Component<Props> {


    onRegionChange(region) {
        this.setState({ region });
    }

    constructor(props){
        super(props);

        this.coordinate = {
            latitude: 35.688442,
            longitude: 51.403753,
            latitudeDelta: LATITUDE_DELTA,
            longitudeDelta: LONGITUDE_DELTA,
        };


        this.state = {
            region : this.coordinate
        }
    }

    render() {
        return (
            <MapView
                region={this.state.region}
                onRegionChangeComplete={this.onRegionChange.bind(this)}
                style={{...StyleSheet.absoluteFillObject}}
            />

        );
    }
}

keth4-fxccc

0 个答案:

没有答案