Ошибка типа: _idex.default.onRegionChange не является функцией - PullRequest
1 голос
/ 23 февраля 2020

[Я создаю собственное приложение реагирования, в котором есть компонент карты и компонент поиска. Компонент поиска и карты отображается в домашнем компоненте. Когда пользователь вводит местоположение, функция getLangLong, доступная в поисковом компоненте, получает новую широту и долготу и передает новый регион через b.onRegionChange (region). Но я получаю сообщение об ошибке «onRegionChange» не является функцией.

Это ошибка, которую я получаю.
This is the error that I am getting.

import React, { Component } from 'react';
import {View, Text } from 'react-native';
import styles from './styles';
import TheMap from 'app/components/map';
import SearchBar from 'app/components/searchBar';

export default class Home extends Component {

  render() {
    return (
      <View style={styles.container}>
        <TheMap />
        <SearchBar />
      </View>
    );
  }
}

     export default class TheMap extends Component{
     constructor(props){
    super(props);
    this.state={
      region: {
       latitude: 45.492409,
      longitude: -73.582153,
      latitudeDelta: 0.0922,
        longitudeDelta: 0.0421
    },
    };
  }

    onRegionChange(region){
    this.setState({ region });
    }
   
    render(){
    return (    
        <View style={styles.container}>
            <MapView 
                onRegionChange={this.onRegionChange.bind(this)}
                region={this.state.region} 
                style={styles.mapStyle} />
        </View>
    );
}
}
 const b=new TheMap();

  async getLatLong(prediction){
    //console.log(prediction);
    const key="MY_API_KEY";
    const geoUrl=`https://maps.googleapis.com/maps/api/place/details/json?key=${key}&placeid=${prediction}`;
    
    try{
    const georesult= await fetch(geoUrl);
    const gjson= await georesult.json();
    this.setState({locations:gjson.result.geometry.location});
    this.setState({
      region:{
      latitude:this.state.locations.lat,
      longitude:this.state.locations.lng,
      latitudeDelta: 0.0922,
        longitudeDelta: 0.0421
      }
      
    });
    b.onRegionChange(this.state.region);

    }
    catch(err){
      console.error(err);
    }
  }
...