Through this code I get the current address of the device:
navigator.geolocation.getCurrentPosition(
(position) => {
this.setState({
latitude: position.coords.latitude,
longitude: position.coords.longitude,
error: null,
}, () => this.getGeocode());
},
(error) => this.setState({ error: error.message }),
{ enableHighAccuracy: true, timeout: 20000 },
);
}
// Retorna o endereço a partir da geolocalização
getGeocode() {
axios.get('https://maps.googleapis.com/maps/api/geocode/json?address='+ this.state.latitude +','+ this.state.longitude +'&key=__API_KEY__')
.then(response => {
console.log(response);
this.setState({
place: response.data.results[0].formatted_address
})
}).catch((error) => {
this.setState({ error: error.message })
});
}
And I print the address in this field:
<Item floatingLabel>
<Label style={{ color: branco }}>Local da ocorrência</Label>
<Input multiline={true} numberOfLines={2} value={this.state.place.toString()} />
</Item>
So that's fine, but I would like it if the user wanted it to delete the address and enter another , but currently, if you try to delete it, it fills up again.
I thought I'd put a button there, like "Enter a different address", but would not it be like simply calling the address once, and can you edit it?