React native 使用React Native maps directions导航到页面时,React Native App将重新启动

React native 使用React Native maps directions导航到页面时,React Native App将重新启动,react-native,expo,react-native-navigation,react-native-maps,React Native,Expo,React Native Navigation,React Native Maps,我正在使用expo和react native。我有大约8个不同的屏幕,但在导航到一个应该显示地图的页面时,应用程序会重新启动并返回初始屏幕。 代码在emulator和my expo应用程序中运行良好。但是错误发生在二进制构建(APK)中。此页面包含来自“反应本机地图”和“反应本机地图方向”的数据 我试着用一个简单的hello world页面来替换这个页面,结果很好。只是这个特定的映射代码没有按预期工作。我正在使用: “expo”:“~37.0.3”,“react”:“~16.9.0”,“reac

我正在使用expo和react native。我有大约8个不同的屏幕,但在导航到一个应该显示地图的页面时,应用程序会重新启动并返回初始屏幕。 代码在emulator和my expo应用程序中运行良好。但是错误发生在二进制构建(APK)中。此页面包含来自“反应本机地图”和“反应本机地图方向”的数据

我试着用一个简单的hello world页面来替换这个页面,结果很好。只是这个特定的映射代码没有按预期工作。我正在使用:

“expo”:“~37.0.3”,“react”:“~16.9.0”,“react native maps”:“0.26.1”,“react native maps directions”:“^1.8.0”

我不明白为什么会这样。我在下面附上了代码。谢谢

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

const { width, height } = Dimensions.get('window');
const ASPECT_RATIO = width / height;
const LATITUDE = 37.771707;
const LONGITUDE = -122.4053769;
const LATITUDE_DELTA = 0.0922;
const LONGITUDE_DELTA = LATITUDE_DELTA * ASPECT_RATIO;

const GOOGLE_MAPS_APIKEY = 'MY_KEY';

class MapScreen extends Component {

  constructor(props) {
    super(props);
    this.state = {
      coordinates: [
        {
          latitude: 12.822960,
          longitude: 80.041929,
        },
        {
          latitude: 13.009027, 
          longitude: 80.222075,
        },
      ],
    };

    this.mapView = null;
  }

  onMapPress = (e) => {
    this.setState({
      coordinates: [
        ...this.state.coordinates,
        e.nativeEvent.coordinate,
      ],
    });
  }

  render() {
    return (
      <MapView
        initialRegion={{
          latitude: LATITUDE,
          longitude: LONGITUDE,
          latitudeDelta: LATITUDE_DELTA,
          longitudeDelta: LONGITUDE_DELTA,
        }}
        style={StyleSheet.absoluteFill}
        ref={c => this.mapView = c}
        onPress={this.onMapPress}
      >
        {this.state.coordinates.map((coordinate, index) =>
          <MapView.Marker key={`coordinate_${index}`} coordinate={coordinate} />
        )}
        {(this.state.coordinates.length >= 2) && (
          <MapViewDirections
            origin={this.state.coordinates[0]}
            destination={this.state.coordinates[this.state.coordinates.length-1]}
            apikey={GOOGLE_MAPS_APIKEY}
            strokeWidth={3}
            strokeColor="hotpink"
            optimizeWaypoints={true}
            onStart={(params) => {
              console.log(`Started routing between "${params.origin}" and "${params.destination}"`);
            }}
            onReady={result => {
              console.log(`Distance: ${result.distance} km`)
              console.log(`Duration: ${result.duration} min.`)

              this.mapView.fitToCoordinates(result.coordinates, {
                edgePadding: {
                  right: (width / 20),
                  bottom: (height / 20),
                  left: (width / 20),
                  top: (height / 20),
                }
              });
            }}
            onError={(errorMessage) => {
              // console.log('GOT AN ERROR');
            }}
          />
        )}
      </MapView>
    );
  }
}

export default MapScreen;
import React,{Component}来自'React';
从“react native”导入{Dimensions,StyleSheet};
从“react native maps”导入MapView;
从“react native maps directions”导入MapViewDirections;
const{width,height}=Dimensions.get('window');
常量纵横比=宽度/高度;
常数纬度=37.771707;
常数经度=-122.4053769;
常数纬度δ=0.0922;
常数经度_δ=纬度_δ*纵横比;
const GOOGLE_MAPS_APIKEY='MY_KEY';
类MapScreen扩展组件{
建造师(道具){
超级(道具);
此.state={
坐标:[
{
纬度:12.822960,
经度:80.041929,
},
{
纬度:13.009027,
经度:80.222075,
},
],
};
this.mapView=null;
}
onappress=(e)=>{
这是我的国家({
坐标:[
…这个州坐标,
e、 nativeEvent.coordinate,
],
});
}
render(){
返回(
this.mapView=c}
onPress={this.onMapPress}
>
{this.state.coordinates.map((坐标,索引)=>
)}
{(this.state.coordinates.length>=2)&&(
{
log(`在“${params.origin}”和“${params.destination}”之间开始路由';
}}
onReady={result=>{
log(`Distance:${result.Distance}km`)
console.log(`Duration:${result.Duration}min.`)
此.mapView.fitToCoordinates(结果.coordinates{
边缘添加:{
右:(宽度/20),
底部:(高度/20),
左:(宽度/20),
顶部:(高度/20),
}
});
}}
OneError={(errorMessage)=>{
//log('GOT-ERROR');
}}
/>
)}
);
}
}
导出默认地图屏幕;