Browse Source

preventing null in the address

master
analuizaff 4 years ago
parent
commit
e2b9292180
  1. 6
      src/app/context/CurrentLocationContext.js
  2. 8
      src/app/screens/MapFormScreen.js

6
src/app/context/CurrentLocationContext.js

@ -37,9 +37,13 @@ const CurrentLocationProvider = ({ children }) => {
// console.log("PEGANDO ENDEREÇO");
Location.setGoogleApiKey("AIzaSyD_wuuokS3SVczc8qSASrsBq0E5qIpdyMc");
const address = await Location.reverseGeocodeAsync(coordenadas);
if (address[0] != undefined) {
setCurrentLocation(address[0].street + ", " + address[0].name + "\n" + address[0].district, coordenadas.x);
var street = (address[0].street == null ? "" : address[0].street);
var number = (address[0].name == null ? "" : address[0].name);
var district = (address[0].district == null ? "" : address[0].district);
setCurrentLocation(street + ", "+ number + "\n" + district , coordenadas.x);
}
else{//Quando o usuário não da permissão de acesso da localização o geoCode retorna um array vazio
setCurrentLocation("Erro ao carregar localização", coordenadas.x);

8
src/app/screens/MapFormScreen.js

@ -23,10 +23,10 @@ const MapFormScreen = (props) => {
const address = await Location.reverseGeocodeAsync(coordenadas);
if (address[0] != undefined) {
context.saveNewLocation(
address[0].street + ", " + address[0].name + "\n" + address[0].district,
coordenadas
);
var street = (address[0].street == null ? "" : address[0].street);
var number = (address[0].name == null ? "" : address[0].name);
var district = (address[0].district == null ? "" : address[0].district);
context.saveNewLocation(street + ", " + number + "\n" + 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);

Loading…
Cancel
Save