"[object Object]" when passing coordinates in React-Native

0

Take a code on the internet where I can get the city where the user is, works perfectly ... Putting only (41.89, 12.49), it finds the city of Rome, the problem is that when I use another coordinate it returns

  

[object Object]

getData(){
Geocoder.init('XXXXXXXXXXX');

Geocoder.getFromLatLng(41.89, 12.49).then(
  json => {
    var address_component = json.results[0].address_components[1];
    console.log(address_component)
    alert(address_component["long_name"]);
  },
  error => {
    alert(error);
  }
);

}

If I put these coordinates

  

Latitude: -30.0277, Longitude: -51.2287   It gives error

Follow, my code:

import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View, AsyncStorage, TextInput, Dimensions } from 'react-native';
import { Actions } from 'react-native-router-flux';
import Geocoder from 'react-native-geocoding';

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

getData(){
    Geocoder.init('XXXXXXXXX'); // use a valid API key

    Geocoder.getFromLatLng(41.89, 12.49).then(
      json => {
        var address_component = json.results[0].address_components[1];
        console.log(address_component)
        alert(address_component["long_name"]);
      },
      error => {
        alert(error);
      }
    );

   }

  constructor(props) {
    super(props);
    this.state = { msg: null , email: null, senha: null, cidade: null,latitude: 0 , longitude: 0 }

  }

    componentDidMount(){
      this.getData();
    }


  render() {
     return (
      <View style={styles.container}>
        <View>
         <TextInput style={styles.campoCidade}
           placeholder="Cidade"
           onChangeText={texto => this.state.cidade = texto }
         />
        </View>

      </View>
    );
  }
}
    
asked by anonymous 19.12.2018 / 18:48

0 answers