0
I’m using the google maps API to do the reverse geocoding
but I’m not getting the formatted_address
import React, { Component } from 'react';
import {
Platform,
Text,
View
} from 'react-native';
import axios from 'axios';
export default class App extends Component<{}> {
constructor(props) {
super(props);
this.state = {
latitude: null,
longitude: null,
place: 'Localizando endereço...',
error: null,
};
}
componentWillMount() {
navigator.geolocation.getCurrentPosition(
(position) => {
this.setState({
latitude: position.coords.latitude,
longitude: position.coords.longitude,
error: null,
});
},
(error) => this.setState({ error: error.message }),
{ enableHighAccuracy: true, timeout: 20000 },
);
axios.get('https://maps.googleapis.com/maps/api/geocode/json?address='+ this.state.latitude +','+ this.state.longitude +'&key=AIzaSyDtQ0zsYr1c_V7UmlHFekeFIGM2nDwnDEA')
.then(results => {
this.setState({
place: results[0].formated_address
})
.catch((error) => {
this.setState({ error: error.message })
});
});
}
render() {
return (
<View style={{ flexGrow: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Latitude: {this.state.latitude}</Text>
<Text>Longitude: {this.state.longitude}</Text>
<Text>{this.state.place.toString()}</Text>
{this.state.error ? <Text>Error: {this.state.error}</Text> : null}
</View>
);
}
}
How do I do?
It’s not, it was the format of the return that was wrong, it has to be like this:
response.data.results[0].formatted_address
– Mateus