Browse Source

adding condition on reverseGeoCode if it can't return address

master
analuizaff 4 years ago
parent
commit
35f31a81b9
  1. 6
      src/app/screens/MapFormScreen.js

6
src/app/screens/MapFormScreen.js

@ -19,13 +19,19 @@ const MapFormScreen = (props) => {
const location = contextLocation.currentCoordinates;
const [marker, setMarker] = useState(context.eventCoordinates);
// console.log(marker);
const getAddress = async (coordenadas) => {
Location.setGoogleApiKey("AIzaSyD_wuuokS3SVczc8qSASrsBq0E5qIpdyMc");
const address = await Location.reverseGeocodeAsync(coordenadas);
if (address[0] != undefined) {
context.saveNewLocation(address[0].street + ", " + address[0].name + "\n" + address[0].district, coordenadas);
}
else{//Quando o usuário não da permissão de acesso da localização o geoCode retorna um array vazio
context.saveNewLocation("Erro ao carregar endereço", coordenadas);
}
}
const setLocation = () => {
getAddress(marker);

Loading…
Cancel
Save